【问题标题】:npm run error react jsnpm 运行错误反应 js
【发布时间】:2017-12-22 22:27:48
【问题描述】:

我正在学习 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 │ └────────────────────────────────────────────────── ──────────┘

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

【问题讨论】:

    标签: node.js reactjs npm npm-start


    【解决方案1】:

    您好像忘记导出配置了

    // webpack.config.js
    
    var config = {
     ...
    
    }; 
    
    // you need to export config object
    module.exports = config
    

    【讨论】:

    • module && module.exports 不同?
    • @hir 你是什么意思? config.module?我的意思是你需要从webpack.config.js 文件中导出整个config 对象。
    猜你喜欢
    • 2019-05-08
    • 1970-01-01
    • 2021-09-07
    • 2018-10-10
    • 2020-03-21
    • 1970-01-01
    • 1970-01-01
    • 2018-07-21
    • 2018-10-05
    相关资源
    最近更新 更多