npm run dev和npm run build报错解决,node install 后 node升级导致报错解决,吃亏总结!

npm run dev

第一种错误

npm ERR! code ELIFECYCLE 
npm ERR! errno 2 
npm ERR! @ development: cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js
npm ERR! Exit status 2 
npm ERR! 
npm ERR! Failed at the @ development 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/sunny/.npm/_logs/2017-12-21T17_00_33_319Z-debug.log 

解决:

npm install -g vue-cli     //window 使用此命令

npm install --global vue-cli     //Linux 使用此命令   2.9+版本

npm uninstall -g vue-cli     //卸载vue-cli

npm install -g @vue/cli     //安装最新版vue-cli    4.0+版本

检测是否安装成功,输入

vue -V

第二种错误
nuxt-test@1.0.0 dev /root/workspace/ackh_dcc/nuxt_dcc
cross-env NODE_ENV=development nodemon server/index.js --watch server

_sh: cross-env: command not found*_
_npm ERR! code ELIFECYCLE_
*npm ERR! syscall spawn*
*npm ERR! file sh*
*npm ERR! errno ENOENT*
*npm ERR! nuxt-test@1.0.0 dev: `cross-env NODE_ENV=development nodemon server/index.js --watch*server`*
*npm ERR! spawn ENOENT*
*npm ERR!*
*npm ERR! Failed at the nuxt-test@1.0.0 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!     /root/.npm/_logs/2020-07-26T23_53_00_259Z-debug.log*

原因: 这里网上一般会说你要做的,只是将你的package.json文件中的cross-env删掉即可:

"dev": "node  NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "node NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch-poll": "node NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --watch-poll --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"hot": "node NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
"production": "node NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"

其实这不太正确,更可能造成另一个错误的方法!!!!!!!!!!!!
你会发现输入npm run dev是可以运行的,只是加在client进度条时候会卡着80到90%之间
然后报错:如下

node_modules\nuxt\lib\core\middleware\nuxt.js:72
      const policies = this.options.render.csp.policies ? {...this.options.render.csp.policies} : null
                                                           ^^^
SyntaxError: Unexpected token ...
    at createScript (vm.js:74:10)
    at Object.runInThisContext (vm.js:116:10)
    at Module._compile (module.js:533:28)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Module.require (module.js:513:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> 
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! nuxt-lockcenterwebsite@1.0.0 dev: `nuxt`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the nuxt-lockcenterwebsite@1.0.0 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:

原因:
node.js版本太低造成的,据说升级到8.6以上就可以了(本人直接12.16.1)
升级版本攻略centos:
https://jingyan.baidu.com/article/5552ef471ffcd7108efbc906.html
windows:网上一堆
继续:
npm run dev

又报错!!!!!!! 无语吧- -

ERROR in ./assets/css/common.scss (./node_modules/css-loader/dist/cjs.js??ref--7-oneOf-1-1!./node_modules/postcss-loader/src??ref--7-oneOf-1-2!./node_modules/sass-loader/dist/cjs.js??ref--7-oneOf-1-3!./assets/css/common.scss)
Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
Error: Missing binding /root/workspace/ackh_dcc/nuxt_dcc/node_modules/node-sass/vendor/linux-x64-72/binding.node
Node Sass could not find a binding for your current environment: Linux 64-bit with Node.js 12.x
Found bindings for the following environments:
  - Linux 64-bit with Node.js 8.x
This usually happens because your environment has changed since running `npm install`.
Run `npm rebuild node-sass` to download the binding for your current environment.
    at module.exports (/root/workspace/ackh_dcc/nuxt_dcc/node_modules/node-sass/lib/binding.js:15:13)
    at Object.<anonymous> (/root/workspace/ackh_dcc/nuxt_dcc/node_modules/node-sass/lib/index.js:14:35)
    at Module._compile (internal/modules/cjs/loader.js:1156:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
    at Module.load (internal/modules/cjs/loader.js:1000:32)
    at Function.Module._load (internal/modules/cjs/loader.js:899:14)
    at Module.require (internal/modules/cjs/loader.js:1042:19)
    at require (internal/modules/cjs/helpers.js:77:18)
    at getDefaultSassImplementation (/root/workspace/ackh_dcc/nuxt_dcc/node_modules/sass-loader/dist/getDefaultSassImplementation.js:24:10)
    at getSassImplementation (/root/workspace/ackh_dcc/nuxt_dcc/node_modules/sass-loader/dist/getSassImplementation.js:19:72)

==解决方法:==其实已经提示了
This usually happens because your environment has changed since running npm install.
原本node v8.x 更新后 node v12.x,但是express启动还是卡主了。
网上的解决方法
解决方式①是需要重装node-sass包
所以呢
···
npm rebuild node-sass
···
重新启动

如果还是 报错!
保存后 删除之前安装失败的包(第一次安装请跳过此步)
npm uninstall node-sass
重新安装
npm install node-sass
npm rebuild node-sass
安装完重新启动就ok了

解决方式②
ls 项目目录 将node_modules 文件夹删除
然后执行 npm i 或者npm install;
然后npm run dev 成功

所以没事还是别更新node,最好保持团队的环境一致~

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

叶孤崖

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值