无法运行npm run build或npm start。

7
每当我尝试构建我的web-pack文件或启动web-pack开发服务器时,都会出现错误。它曾经工作过,但是我在处理eslint时弄坏了什么东西。
这是在尝试使用“npm build”时出现的错误包。
0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'run', 'build' ]
2 info using npm@4.5.0
3 info using node@v6.10.3
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle setup@1.0.0~prebuild: setup@1.0.0
6 silly lifecycle setup@1.0.0~prebuild: no script for prebuild, continuing
7 info lifecycle setup@1.0.0~build: setup@1.0.0
8 verbose lifecycle setup@1.0.0~build: unsafe-perm in lifecycle true
9 verbose lifecycle setup@1.0.0~build: PATH: /usr/local/lib/node_modules/npm/bin/node-gyp-bin:/Users/Nims/Documents/Web Development/Projects/React bookstore/node_modules/.bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
10 verbose lifecycle setup@1.0.0~build: CWD: /Users/Nims/Documents/Web Development/Projects/React bookstore
11 silly lifecycle setup@1.0.0~build: Args: [ '-c', 'webpack' ]
12 silly lifecycle setup@1.0.0~build: Returned: code: 1  signal: null
13 info lifecycle setup@1.0.0~build: Failed to exec build script
14 verbose stack Error: setup@1.0.0 build: `webpack`
14 verbose stack Exit status 1
14 verbose stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/lifecycle.js:279:16)
14 verbose stack     at emitTwo (events.js:106:13)
14 verbose stack     at EventEmitter.emit (events.js:191:7)
14 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/spawn.js:40:14)
14 verbose stack     at emitTwo (events.js:106:13)
14 verbose stack     at ChildProcess.emit (events.js:191:7)
14 verbose stack     at maybeClose (internal/child_process.js:886:16)
14 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)
15 verbose pkgid setup@1.0.0
16 verbose cwd /Users/Nims/Documents/Web Development/Projects/React bookstore
17 verbose Darwin 16.5.0
18 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "build"
19 verbose node v6.10.3
20 verbose npm  v4.5.0
21 error code ELIFECYCLE
22 error errno 1
23 error setup@1.0.0 build: `webpack`
23 error Exit status 1
24 error Failed at the setup@1.0.0 build script 'webpack'.
24 error Make sure you have the latest version of node.js and npm installed.
24 error If you do, this is most likely a problem with the setup package,
24 error not with npm itself.
24 error Tell the author that this fails on your system:
24 error     webpack
24 error You can get information on how to open an issue for this project with:
24 error     npm bugs setup
24 error Or if that isn't available, you can get their info via:
24 error     npm owner ls setup
24 error There is likely additional logging output above.
25 verbose exit [ 1, true ]

当尝试运行 npm start 时

0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'start' ]
2 info using npm@4.5.0
3 info using node@v6.10.3
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle setup@1.0.0~prestart: setup@1.0.0
6 silly lifecycle setup@1.0.0~prestart: no script for prestart, continuing
7 info lifecycle setup@1.0.0~start: setup@1.0.0
8 verbose lifecycle setup@1.0.0~start: unsafe-perm in lifecycle true
9 verbose lifecycle setup@1.0.0~start: PATH: /usr/local/lib/node_modules/npm/bin/node-gyp-bin:/Users/Nims/Documents/Web Development/Projects/React bookstore/node_modules/.bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
10 verbose lifecycle setup@1.0.0~start: CWD: /Users/Nims/Documents/Web Development/Projects/React bookstore
11 silly lifecycle setup@1.0.0~start: Args: [ '-c', 'webpack-dev-server' ]
12 silly lifecycle setup@1.0.0~start: Returned: code: 1  signal: null
13 info lifecycle setup@1.0.0~start: Failed to exec start script
14 verbose stack Error: setup@1.0.0 start: `webpack-dev-server`
14 verbose stack Exit status 1
14 verbose stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/lifecycle.js:279:16)
14 verbose stack     at emitTwo (events.js:106:13)
14 verbose stack     at EventEmitter.emit (events.js:191:7)
14 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/spawn.js:40:14)
14 verbose stack     at emitTwo (events.js:106:13)
14 verbose stack     at ChildProcess.emit (events.js:191:7)
14 verbose stack     at maybeClose (internal/child_process.js:886:16)
14 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)
15 verbose pkgid setup@1.0.0
16 verbose cwd /Users/Nims/Documents/Web Development/Projects/React bookstore
17 verbose Darwin 16.5.0
18 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "start"
19 verbose node v6.10.3
20 verbose npm  v4.5.0
21 error code ELIFECYCLE
22 error errno 1
23 error setup@1.0.0 start: `webpack-dev-server`
23 error Exit status 1
24 error Failed at the setup@1.0.0 start script 'webpack-dev-server'.
24 error Make sure you have the latest version of node.js and npm installed.
24 error If you do, this is most likely a problem with the setup package,
24 error not with npm itself.
24 error Tell the author that this fails on your system:
24 error     webpack-dev-server
24 error You can get information on how to open an issue for this project with:
24 error     npm bugs setup
24 error Or if that isn't available, you can get their info via:
24 error     npm owner ls setup
24 error There is likely additional logging output above.
25 verbose exit [ 1, true ]

这是我的webpack文件。
module.exports = {
  entry: ['babel-polyfill', './app/index.js'],
  output: {
    path: __dirname + '/build',
    // if the above line does not work, try `path: __dirname + '/build'`
    filename: 'bundle.js'
  },
  module: {
    loaders: [
      {
        test: /\.js$/, // a regular expression that catches .js files
        exclude: /node_modules/,
        loader: ['babel-loader']
      }
    ],
  },
  devServer: {
    port: 3000, // most common port
    contentBase: './build',
    inline: true
  }
};

看起来我的 webpack.config.js 文件没有捕捉到本地脚本 - 但是我还是新手,正在学习中。


只是想确认一下您是否运行了 npm install?如果是的话,那就删除 node_modules 文件夹,然后再次运行 npm install - Matt Shirley
感谢@MattShirley - 我再次运行npm install,但是我需要先删除节点模块文件夹。 - Nims
2个回答

1
尝试删除node_modules,然后运行该脚本。

0

可能尚未在npm全局安装,需要单独安装它们,然后以非root权限运行常规的npm install命令:

sudo npm install -g coffee-script node-gyp
npm install

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接