当前位置: 首页 > 工具软件 > script-server > 使用案例 >

npm start后报错cross-env NODE_ENV=demo webpack-dev-server 的解决

景阳曜
2023-12-01

拉取了项目后,cnpm install安装依赖,然后再npm start运行报错:

Error: spawn webpack-dev-server ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:240:19)
at onErrorNT (internal/child_process.js:415:16)
at process._tickCallback (internal/process/next_tick.js:63:19)
at Function.Module.runMain (internal/modules/cjs/loader.js:832:11)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
Emitted 'error' event at:
at Process.ChildProcess._handle.onexit (internal/child_process.js:246:12)
at onErrorNT (internal/child_process.js:415:16)
[... lines matching original stack trace ...]
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! react-antd@1.0.0 start: `cross-env NODE_ENV=demo webpack-dev-server --open --config ./webpack-config/webpack.dev.js --progress`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the react-antd@1.0.0 start 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/oyo/.npm/_logs/2019-07-23T02_52_17_481Z-debug.log

 

自己百度了半天,从第一句话“Error: spawn webpack-dev-server ENOENT”也知道是webpack-dev-server的问题,大概是版本问题,但重新安装后就是不行,问了一下老大终于解决了。

解决思路:

首先安装但时候需要-g,因为webpack-dev-server是全局的。

说一下“cross-env NODE_ENV=demo webpack-dev-server --open --config ”这句话。从cross-env也可以看出来webpack-dev-server是全局的,因为cross-env是为了windows兼容的。cross-env也可以删掉,无所谓的。后面的“--open --config”都是参数,只要是“--”开头,都是参数。所以主要还是webpack-dev-server的问题。

 

老大的具体操作流程:

1.删除项目文件夹中node_modules文件夹

2.npm i

3.npm run start(这时报错了)

4.sudo npm i webpack-dev-server -g 

5.输入密码

页面就出来啦~

转载于:https://www.cnblogs.com/sherrycat/p/11230608.html

 类似资料: