gpt4 book ai didi

javascript - Uncaught Error : Minified React error #130

转载 作者:行者123 更新时间:2023-11-30 06:55:04 33 4
gpt4 key购买 nike

我的代码是这样的

----------index.js-----

var React =require('react');
var ReactDOM =require('react-dom');
var App=require('../components/App');

ReactDOM.render(<App />, document.getElementById('app'));

----------App.js-----

var React = require('react');

class App extends React.Component {
render() {
return(
<div>
<h1>HI wassup</h1>
</div>
);
}
}
export default App;

---------package.json-----

{
"name": "views",
"version": "1.0.0",
"description": "learning",
"main": "index.js",
"scripts": {
"start": "webpack-dev-server --mode development --hot && webpack"
},
"author": "vinayak",
"license": "ISC",
"dependencies": {
"react": "^16.4.2",
"react-dom": "^16.4.2"
},
"devDependencies": {
"babel-core": "^6.26.3",
"babel-loader": "^7.1.5",
"babel-preset-react": "^6.24.1",
"html-webpack-plugin": "^3.2.0",
"unminified-webpack-plugin": "^2.0.0",
"webpack": "^4.16.5",
"webpack-cli": "^3.1.0",
"webpack-dev-server": "^3.1.5"
}
}

--------webpackconfig-----

const HTMLWebpackPlugin=require('html-webpack-plugin');
const webpack=require('webpack');
const UnminifiedWebpackPlugin = require('unminified-webpack-plugin');
const HTMLWebpackPluginConfig=new HTMLWebpackPlugin({
template: '../../views/index.hbs',
filename:'index.hbs'
});

module.exports={
entry:__dirname + '/app/index.js',
module:{
rules:[
{
test:/\.js$/,
exclude:/node_modules/,
loader:'babel-loader'
}
]
},
plugins: [
new UnminifiedWebpackPlugin(),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('development')
}
})
],
devtool: 'source-map',
output:{
filename:'app.js',
path:__dirname + '../../public/javascripts/'
},
devServer:{
inline:false
}

};

----------------文件夹结构------------

|react
|node modules
|components
|App.js
|app
|index.js

一切正常,但是当我在浏览器中执行应用程序时,出现 react 错误并提供显示以下内容的链接。

"Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object."

最佳答案

您混淆了 requireimport/export

由于您正在运行 webpack,因此您的所有 React 代码(以及任何通过 webpack 由 babel 转译的代码)都应该坚持使用导入/导出。 require应该只用在像js这种直接由node运行的地方。

在您的 index.js 中,将所有要求更改为导入,看看是否有帮助。

关于javascript - Uncaught Error : Minified React error #130,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51803969/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com