我是React和nodeJS的新手,我在webpack和npm方面遇到了一些问题。我已尝试根据本教程配置我的localhost:https://www.tutorialspoint.com/reactjs/reactjs_environment_setup.htm
当我写入cmd:" npm start"它会抛出以下信息(在图片上)。我已经安装了webpack,但它说它没有认识到它。什么是#34;奇怪的错误"顺便说说? 你能给我一些链接,我可以正确配置我的机器吗?
我的webpack.config.js文件:
var config = {
entry: './main.js',
output: {
path:'./',
filename: 'index.js',
},
devServer: {
inline: true,
port: 8080
},
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel',
query: {
presets: ['es2016', 'react']
}
}
]
}
}
module.exports = config;
package.json文件:
{
"name": "reactApp",
"version": "0.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "webpack-dev-server --hot"
},
"author": "",
"license": "BSD"
}
答案 0 :(得分:0)
我认为错误信息是匈牙利语,但从我看到的情况来看,我猜系统无法找到webpack-dev-server。
尝试使用npm install --save-dev webpack-dev-server
在本地安装它。确保它在node_modules/.bin/webpack-dev-server
内。如果您的控制台说找不到该命令,请尝试运行node_modules/.bin/webpack-dev-server
有关webpack-dev-server安装的更多信息,请参阅此处:https://webpack.js.org/guides/development/#webpack-dev-server
==================
编辑:关于新错误,正如在控制台中所说,您需要在webpack.config.js中将后缀-loader
添加到babel
var config = {
entry: './main.js',
output: {
path:'./',
filename: 'index.js',
},
devServer: {
inline: true,
port: 8080
},
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel-loader',
query: {
presets: ['es2016', 'react']
}
}
]
}
}
module.exports = config;