node不管你喜不喜欢、有没有了解过,但在项目中却总是会用到,开源的集成太多了.不管是哪一个框架,composer安装后,总会给你集成一大堆的东西,不管你有没有了解过,后期开发会不会用到,全给你集成进去了(因为框架会用到)。

laravel也是带这样的坑,laravel使用了mix,必须要用到node,没啥关系的两种开发环境,就这样硬集成一块去了。node环境出问题,影响了laravel无法正常安装使用,你明明用的是laravel,但却要去解决node的问题。坑不坑?其实挺坑的!

回到正题,还是laravel-shop的安装问题,换了一台机,又得重新再安装一遍,前台页面还是报Mix错误,查了node跟npm的版本,比较低,npm install -g npm升级又升级不了!执行npm命令(任何一个),就报以下这个错:

zu@he:/var/www/html/laravel-shop$ npm update
/usr/local/lib/node_modules/npm/bin/npm-cli.js:85
let notifier = require('update-notifier')({pkg})
^^^
SyntaxError: Block-scoped declarations (let, const, function, class) 
not yet supported outside strict modeat exports.runInThisContext 
(vm.js:53:16)at Module._compile (module.js:374:25)at Object.Module._extensions..js 
(module.js:417:10)at Module.load (module.js:344:32)at Function.Module._load (module.js:301:12)at Function.Module.runMain
(module.js:442:10)at startup (node.js:136:18)at node.js:966:3
主要是npm,不管什么命令都给报这个错

估计是版本问题,执行以下方法升级node了。

zu@he:sudo apt-get remove nodejs
zu@he:curl -sL https://deb.nodesource.com/setup_8.x | sudo bash
zu@he:sudo apt-get update
zu@he:sudo apt-get install nodejs
zu@he:sudo npm install npm -g
#完成后node为v8.17.0版,npm为6.13.4

再重新在网站根目录删除node_modules后,再执行npm install,却一直报下面的错误

npm WARN tarball tarball data for [email protected] (sha1-DBxPBwC+2NvBJM2zBNJZLKID5nc=) seems to be corrupted. Trying one more time.
npm WARN tarball tarball data for [email protected] (sha1-4Bl16BJ4GhY6ba392AOY3GTIicM=) seems to be corrupted. Trying one more time.
npm WARN tarball tarball data for [email protected] (sha1-k8WjrP2+8nUiCtcmRK0C7hg2jeE=) seems to be corrupted. Trying one more time.
npm WARN tarball tarball data for [email protected] (sha1-ut+hSX1GJE9jkPWLMZgw2RB4U8U=) seems to be corrupted. Trying one more time.
npm WARN tarball tarball data for [email protected] (sha1-ut+hSX1GJE9jkPWLMZgw2RB4U8U=) seems to be corrupted. Trying one more time.
npm WARN tarball tarball data for [email protected] (sha1-ut+hSX1GJE9jkPWLMZgw2RB4U8U=) seems to be corrupted. Trying one more time.
npm ERR! code EAI_AGAIN
npm ERR! errno EAI_AGAIN
npm ERR! request to http://registry.npm.taobao.org/schema-utils/download/schema-utils-0.4.7.tgz failed, reason: getaddrinfo EAI_AGAIN registry.npm.taobao.org:80
npm WARN tar ENOENT: no such file or directory, open '/var/www/html/laravel-shop/node_modules/.staging/postcss-97c9ec6c/lib/comment.js'
npm WARN tar ENOENT: no such file or directory, open '/var/www/html/laravel-shop/node_modules/.staging/postcss-97c9ec6c/lib/previous-map.js'
npm WARN tar ENOENT: no such file or directory, open '/var/www/html/laravel-shop/node_modules/.staging/postcss-97c9ec6c/lib/processor.js'
npm WARN tar ENOENT: no such file or directory, open '/var/www/html/laravel-shop/node_modules/.staging/postcss-69fa6fb1/lib/map-generator.js'
npm WARN tarball tarball data for [email protected] (sha1-ut+hSX1GJE9jkPWLMZgw2RB4U8U=) seems to be corrupted. Trying one more time.
npm WARN tarball tarball data for [email protected] (sha1-ut+hSX1GJE9jkPWLMZgw2RB4U8U=) seems to be corrupted. Trying one more time.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/zhou/.npm/_logs/2020-01-06T07_47_33_935Z-debug.log

是终解决方案:

#使用其它的镜像,之前用了淘宝的,切换dns为233.5.5.5都不行,再换为其它的吧!
npm config set registry http://r.cnpmjs.org
#完成后,重新执行install
npm cache verify && npm install
#最后重新启动一下npm
npm run production

最后感谢一下以下作者

npm使用过程中的一些错误解决办法及npm常用命令和技巧 - 世有因果知因求果 - 博客园
node,npm在前端开发流程中提供了非常完善的自动化工具链,但是同样由于其复杂性导致有很多奇奇怪怪的问题。本文将记录使用过程中出现的一些问题及其解决方法备案。 国内由于gfw问题,导致很多国外的网站