npm运行错误反应js

时间:2017-07-18 07:28:58

标签: node.js reactjs npm npm-start

我正在学习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运行或访问│ │通过│到本地更新配置存储 │sudochown -R $ USER:$(id -gn $ USER)/home/me/.config│ └───────────────────────────────────────────────── ─────────┘

    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"]
            }

    }
 ]
 }

 };

的package.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"
    },

1 个答案:

答案 0 :(得分:0)

您好像忘记导出配置

// webpack.config.js

var config = {
 ...

}; 

// you need to export config object
module.exports = config