blog
blog copied to clipboard
pm2 deploy 时总是报无法找到某个模块
本地package.json文件都有这些模块,但是拉去代码到服务器之后执行deploy就报这个错误,到服务器端到production文件夹去看时没问题的
--> Deploying to production environment --> on host 39.105.73.230 fatal: no upstream configured for branch 'master' ○ deploying origin/master ○ executing pre-deploy-local ○ hook pre-deploy ○ fetching updates ○ full fetch Fetching origin ○ resetting HEAD to origin/master HEAD is now at c22d75d fix ○ executing post-deploy
export NODE_ENV=production && cnpm install && node build/build.js && pm2 startOrRestartecosystem.json --env production`
[1/15] fastclick@^1.0.6 installed at node_modules/[email protected]@fastclick
[2/15] lyric-parser@^1.0.1 installed at node_modules/[email protected]@lyric-parser
[3/15] js-base64@^2.1.9 installed at node_modules/[email protected]@js-base64
[4/15] jsonp@^0.2.1 installed at node_modules/[email protected]@jsonp
[5/15] good-storage@^1.0.1 installed at node_modules/[email protected]@good-storage
[6/15] vue-lazyload@^1.0.5 installed at node_modules/[email protected]@vue-lazyload
[7/15] axios@^0.16.2 installed at node_modules/[email protected]@axios
[8/15] better-scroll@^0.4.0 installed at node_modules/[email protected]@better-scroll
[9/15] vue-router@^2.3.1 installed at node_modules/[email protected]@vue-router
[10/15] socks@^2.2.1 installed at node_modules/[email protected]@socks
[11/15] vuex@^2.3.1 installed at node_modules/[email protected]@vuex
[12/15] vue@^2.3.3 installed at node_modules/[email protected]@vue
[13/15] create-keyframe-animation@^0.1.0 installed at node_modules/[email protected]@create-keyframe-animation
[14/15] babel-runtime@^6.23.0 installed at node_modules/[email protected]@babel-runtime
[15/15] babel-polyfill@^6.23.0 installed at node_modules/[email protected]@babel-polyfill
Recently updated (since 2018-07-28): 2 packages (detail see file /home/zsz_user/www/website/production/source/node_modules/.recently_updates.txt)
2018-08-02
→ [email protected] › follow-redirects@^1.2.3(1.5.2) (02:34:57)
→ vue@^2.3.3(2.5.17) (03:31:34)
All packages installed (42 packages installed from npm registry, used 2s(network 2s), speed 1.58MB/s, json 40(387.09kB), tarball 2.18MB)
module.js:471
throw err;
^
Error: Cannot find module 'chalk'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.
post-deploy hook failed
Deploy failed`
可以试下采用 npm 替换 cnpm 进行安装
我又检查了下发现执行npm命令安装package的时候,只安装了dependencies的包,但是devDependencies的包却没有安装,只能手动到服务器里面去安装才行代码如下
--> Deploying to production environment --> on host 39.105.73.230 fatal: no upstream configured for branch 'master' ○ deploying origin/master ○ executing pre-deploy-local ○ hook pre-deploy ○ fetching updates ○ full fetch Fetching origin ○ resetting HEAD to origin/master HEAD is now at b422d5e fix ○ executing post-deploy
export NODE_ENV=production && cnpm install && npm run build && pm2 startOrRestart ecosystem.json --env production`
[1/15] lyric-parser@^1.0.1 installed at node_modules/[email protected]@lyric-parser
[2/15] fastclick@^1.0.6 installed at node_modules/[email protected]@fastclick
[3/15] js-base64@^2.1.9 installed at node_modules/[email protected]@js-base64
[4/15] vue-lazyload@^1.0.5 installed at node_modules/[email protected]@vue-lazyload
[5/15] good-storage@^1.0.1 installed at node_modules/[email protected]@good-storage
[6/15] jsonp@^0.2.1 installed at node_modules/[email protected]@jsonp
[7/15] axios@^0.16.2 installed at node_modules/[email protected]@axios
[8/15] better-scroll@^0.4.0 installed at node_modules/[email protected]@better-scroll
[9/15] vue-router@^2.3.1 installed at node_modules/[email protected]@vue-router
[10/15] socks@^2.2.1 installed at node_modules/[email protected]@socks
[11/15] vuex@^2.3.1 installed at node_modules/[email protected]@vuex
[12/15] vue@^2.3.3 installed at node_modules/[email protected]@vue
[13/15] create-keyframe-animation@^0.1.0 installed at node_modules/[email protected]@create-keyframe-animation
[14/15] babel-runtime@^6.23.0 installed at node_modules/[email protected]@babel-runtime
[15/15] babel-polyfill@^6.23.0 installed at node_modules/[email protected]@babel-polyfill
Recently updated (since 2018-07-29): 2 packages (detail see file /home/zsz_user/www/website/production/source/node_modules/.recently_updates.txt)
2018-08-02
→ [email protected] › follow-redirects@^1.2.3(1.5.2) (02:34:57)
→ vue@^2.3.3(2.5.17) (03:31:34)
All packages installed (42 packages installed from npm registry, used 2s(network 2s), speed 1.63MB/s, json 40(483.35kB), tarball 2.18MB)
[email protected] build /home/zsz_user/www/website/production/source node build/build.js
module.js:471 throw err; ^
Error: Cannot find module 'chalk'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.node build/build.js
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] build 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! /home/zsz_user/.npm/_logs/2018-08-04T16_37_18_210Z-debug.log
post-deploy hook failed
Deploy failed`
使用这个命令在服务器上再次确认一下是否只安装了 dependencies 中的依赖:npm list --depth=0 2>/dev/null
或 yarn list --depth=0 2>/dev/null
,这个问题我也偶尔遇到过,有时候也会在服务器上重新安装,要不你就换 yarn
试一下去安装依赖