➜ musik git:(master) ✗ npm run dev
> music@0.2.2 dev /Users/macbookair/Workspace/fun/mine/musik
> cross-env NODE_ENV=development webpack-dev-server --open --hot
/Users/macbookair/Workspace/fun/mine/musik/node_modules/webpack-dev-server/bin/webpack-dev-server.js:405
throw e;
^
TypeError: Cannot read property 'compile' of undefined
at addCompilerHooks (/Users/macbookair/Workspace/fun/mine/musik/node_modules/webpack-dev-server/lib/Server.js:71:16)
at new Server (/Users/macbookair/Workspace/fun/mine/musik/node_modules/webpack-dev-server/lib/Server.js:81:5)
at startDevServer (/Users/macbookair/Workspace/fun/mine/musik/node_modules/webpack-dev-server/bin/webpack-dev-server.js:398:14)
at portfinder.getPort (/Users/macbookair/Workspace/fun/mine/musik/node_modules/webpack-dev-server/bin/webpack-dev-server.js:369:5)
at /Users/macbookair/Workspace/fun/mine/musik/node_modules/portfinder/lib/portfinder.js:160:14
at /Users/macbookair/Workspace/fun/mine/musik/node_modules/portfinder/node_modules/async/lib/async.js:52:16
at /Users/macbookair/Workspace/fun/mine/musik/node_modules/portfinder/node_modules/async/lib/async.js:269:32
at /Users/macbookair/Workspace/fun/mine/musik/node_modules/portfinder/node_modules/async/lib/async.js:44:16
at /Users/macbookair/Workspace/fun/mine/musik/node_modules/portfinder/lib/portfinder.js:122:16
at Server.onListen (/Users/macbookair/Workspace/fun/mine/musik/node_modules/portfinder/lib/portfinder.js:45:7)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! music@0.2.2 dev: `cross-env NODE_ENV=development webpack-dev-server --open --hot`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the music@0.2.2 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/macbookair/.npm/_logs/2018-07-19T04_28_44_986Z-debug.log
日志:
0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/Cellar/node/9.8.0/bin/node',
1 verbose cli '/usr/local/bin/npm',
1 verbose cli 'run',
1 verbose cli 'dev' ]
2 info using npm@6.2.0
3 info using node@v9.8.0
4 verbose run-script [ 'predev', 'dev', 'postdev' ]
5 info lifecycle music@0.2.2~predev: music@0.2.2
6 info lifecycle music@0.2.2~dev: music@0.2.2
7 verbose lifecycle music@0.2.2~dev: unsafe-perm in lifecycle true
8 verbose lifecycle music@0.2.2~dev: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/macbookair/Workspace/fun/mine/musik/node_modules/.bin:/U
sers/macbookair/bin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/share/dotnet:/usr/local/go/bin:/Library/Frameworks/Mono.framework/Versions/Current/Comm
ands:/Applications/Xamarin Workbooks.app/Contents/SharedSupport/path-bin:/usr/local/opt/go/libexec/bin
9 verbose lifecycle music@0.2.2~dev: CWD: /Users/macbookair/Workspace/fun/mine/musik
10 silly lifecycle music@0.2.2~dev: Args: [ '-c',
10 silly lifecycle 'cross-env NODE_ENV=development webpack-dev-server --open --hot' ]
11 silly lifecycle music@0.2.2~dev: Returned: code: 1 signal: null
12 info lifecycle music@0.2.2~dev: Failed to exec dev script
13 verbose stack Error: music@0.2.2 dev: `cross-env NODE_ENV=development webpack-dev-server --open --hot`
13 verbose stack Exit status 1
13 verbose stack at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:304:16)
13 verbose stack at EventEmitter.emit (events.js:180:13)
13 verbose stack at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack at ChildProcess.emit (events.js:180:13)
13 verbose stack at maybeClose (internal/child_process.js:936:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:220:5)
14 verbose pkgid music@0.2.2
15 verbose cwd /Users/macbookair/Workspace/fun/mine/musik
16 verbose Darwin 16.7.0
17 verbose argv "/usr/local/Cellar/node/9.8.0/bin/node" "/usr/local/bin/npm" "run" "dev"
18 verbose node v9.8.0
19 verbose npm v6.2.0
20 error code ELIFECYCLE
21 error errno 1
22 error music@0.2.2 dev: `cross-env NODE_ENV=development webpack-dev-server --open --hot`
22 error Exit status 1
23 error Failed at the music@0.2.2 dev script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]
Webpack版本:4.16.1
NPM版本:6.2.0
当我构建生产项目时,没有错误。但是我似乎无法在开发模式下运行它。是什么导致此错误?
答案 0 :(得分:0)
您的错误似乎是某些开发人员依存关系不正确。尝试删除node_modules
文件夹和package-lock.json
文件,然后运行npm install
。