我正在学习 ReactJS。安装已经完成,但是当我运行这个 npm 命令时,我收到以下错误。
me@R-SOFT-85:/var/www/reactjsbasics$ npm run build
> reactjsbasics@1.0.0 build /var/www/reactjsbasics
> webpack -d && cp src/index.html dist/index.html && webpack-dev-server --content-base src/ --inline --watch
/var/www/reactjsbasics/node_modules/webpack/bin/convert-argv.js:487
throw new Error("'output.filename' is required, either in config file or as --output-filename");
^
Error: 'output.filename' is required, either in config file or as --output-filename
at processOptions (/var/www/reactjsbasics/node_modules/webpack/bin/convert-argv.js:487:11)
at processConfiguredOptions (/var/www/reactjsbasics/node_modules/webpack/bin/convert-argv.js:136:4)
at module.exports (/var/www/reactjsbasics/node_modules/webpack/bin/convert-argv.js:112:10)
at Object.<anonymous> (/var/www/reactjsbasics/node_modules/webpack/bin/webpack.js:155:40)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.runMain (module.js:605:10)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! reactjsbasics@1.0.0 build: `webpack -d && cp src/index.html dist/index.html && webpack-dev-server --content-base src/ --inline --watch`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the reactjsbasics@1.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
┌────────────────────────────────────────────────── ────────┐ │ npm 更新检查失败 │ │ 尝试使用 sudo 运行或获取访问权限 │ │ 通过 │ 访问本地更新配置存储 │ sudo chown -R $USER:$(id -gn $USER) /home/me/.config │ └─────────────────────────────────────── ──────────────────┘</p>
npm ERR! A complete log of this run can be found in:
npm ERR! /home/me/.npm/_logs/2017-07-18T06_15_33_602Z-debug.log
webpack.config.js
var webpack=require("webpack");
var path=require("path");
var DIST_DIR = path.resolve(__dirname,"dist");
var SRC_DIR = path.resolve(__dirname,"src");
var config={
entry:SRC_DIR + "/app/index.js",
output:{
path:DIST_DIR+"/app",
filename:"bundle.js",
publicPath:"/app/"
},
module:{
loaders:[
{
test:"/\.js?/",
include:SRC_DIR,
loader:"babel-loader",
query:{
presets:["react","es2015","stage-2"]
}
}
]
}
};
包.json
"scripts": {
"start":"npm run build",
"build":"webpack -d && cp src/index.html dist/index.html && webpack-dev-server --content-base src/ --inline --watch",
"build:prod":"webpack -p && cp src/index.html dist/index.html"
},