したがって、最初のReactJSチュートリアルでは、Ubuntu VMを使用していましたが、reactおよびreact-domの依存関係をインストールするのを忘れたため、この問題が発生したことを覚えています。私は今Windowsを使用していて、すべてをインストールしていることを確認しましたが、同じエラーが発生します。
私のpackage.jsonには、次のものがあります。
{
"name": "github-battle",
"version": "1.0.0",
"description": "",
"main": "webpack.config.js",
"dependencies": {},
"devDependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-preset-env": "^1.6.1",
"babel-preset-react": "^6.24.1",
"css-loader": "^0.28.9",
"html-webpack-plugin": "^2.30.1",
"react": "^16.2.0",
"react-dom": "^16.2.0",
"style-loader": "^0.20.2",
"webpack": "^3.11.0",
"webpack-dev-server": "^2.11.1"
},
"scripts": {
"create": "webpack"
},
"author": "",
"license": "ISC"
}
私のwebpack.config.jsの場合
var path = require('path');
var HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry: './app/index.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'index_bundle.js',
publicPath: '/'
},
module: {
rules: [
{ test: /\.(js)$/, use: 'babel-loader' },
{ test: /\.css$/, use: [ 'style-loader', 'css-loader' ]}
]
},
devServer: {
historyApiFallback: true,
},
plugins: [
new HtmlWebpackPlugin({
template: 'app/index.html'
})
]
};
index.js
var React = require('react');
var ReactDOM = require('react-dom');
require('./index.css');
class App extends React.Component{
render(){
return(
<div>Hello World</div>
)
}
}
ReactDOM.render(<App />, document.getElementById('app'));
Windowsで別の方法でやらなければならないことはありますか?
貼り付けたすべてのファイルを使用して新しいプロジェクトを作成しようとしましたが、同じエラーが発生しました。次の2つのコマンドを実行して解決しました。
npm install --save react
npm install --save react-dom
これを含む.babelrcファイルも追加しました。
{
"presets": ["react"]
}
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加