项目本地完全可以跑起来,但是pm2 deploy发布会报错

来源:1-2 安装跟进最新的 Node.js 版本

拖车板牙爵士

2018-11-08

前提:服务器、window环境、Mac环境安装的node、pm2、mongodb等完全都是同一版本

同样的代码,在公司台式机【window环境】上开发,pm2发布都是没问问题的,完全正常,发布后服务器运行的生产项目也是正常的。

同样的代码,在【window环境】就可以开发、发布,说明【window环境】本地跟服务器环境是没问题的,

但是在【mac环境】下项目在自己本地跑一点问题都没有,然后pm2 deploy ecosystem.json production setup也是成功的,但是在 pm2 deploy ecosystem.json production的时候就会报错,报错内容如下

[PM2] Spawning PM2 daemon with pm2_home=/Users/dylan/.pm2
[PM2] PM2 Successfully daemonized
--> Deploying to production environment
--> on host 116.61.128.61
  ○ deploying origin/master
  ○ executing pre-deploy-local
  ○ hook pre-deploy
  ○ fetching updates
  ○ full fetch
manpath: can't set the locale; make sure $LC_* and $LANG are correct
Fetching origin
  ○ resetting HEAD to origin/master
manpath: can't set the locale; make sure $LC_* and $LANG are correct
HEAD is now at 0d6c3c3 update
manpath: can't set the locale; make sure $LC_* and $LANG are correct
manpath: can't set the locale; make sure $LC_* and $LANG are correct
  ○ executing post-deploy `export NODE_ENV=production && yarn install && npm run build && pm2 startOrRestart ecosystem.json --env production`
manpath: can't set the locale; make sure $LC_* and $LANG are correct
yarn install v1.2.1
[1/4] Resolving packages...
success Already up-to-date.
Done in 0.84s.

> portals@1.0.0 build /www/xi-portals/production/source
> nuxt build && backpack build

2018-11-08T01:52:23.144Z nuxt:build Building...
2018-11-08T01:52:23.538Z nuxt:build App root: /www/xi-portals/production/source
2018-11-08T01:52:23.539Z nuxt:build Generating /www/xi-portals/production/source/.nuxt files...
2018-11-08T01:52:23.596Z nuxt:build Generating files...
2018-11-08T01:52:23.602Z nuxt:build Generating routes...
2018-11-08T01:52:23.621Z nuxt:build Building files...
Hash: aaf80505a99b39af859e
Version: webpack 3.6.0
Time: 9947ms
                                     Asset       Size  Chunks             Chunk Names
    pages/question.830de021e3e2ce13a5d4.js    2.65 kB       4  [emitted]  pages/question
               img/contact_map.448ee22.jpg    36.3 kB          [emitted]
                       img/app.6f8aa37.jpg    44.7 kB          [emitted]
                      img/logo.9d69fe0.png    3.76 kB          [emitted]
                   img/service.bd13b7a.jpg    27.8 kB          [emitted]
pages/product-list.708ef4997d4201d2d400.js    16.5 kB       0  [emitted]  pages/product-list
      pages/detail.9d7a13849aff13febcc0.js    17.5 kB       1  [emitted]  pages/detail
       pages/breed.ad253f63cdd07e4b983d.js    16.3 kB       2  [emitted]  pages/breed
     pages/contact.3b382ce67ee374b93a1e.js    2.35 kB       3  [emitted]  pages/contact
                    img/police.d0289dc.png    19.3 kB          [emitted]
        pages/join.c0287c2c1b330a44c90f.js    2.66 kB       5  [emitted]  pages/join
       pages/index.0a02649a93b97cbddc5e.js    2.29 kB       6  [emitted]  pages/index
    pages/business.821128a92dd38e0a0d92.js    1.99 kB       7  [emitted]  pages/business
       pages/about.9b268e26eb38473d11b4.js    1.77 kB       8  [emitted]  pages/about
   layouts/default.89f45e780b9c48e23854.js    1.15 kB       9  [emitted]  layouts/default
            common.339ff37341e0983a7cbe.js     126 kB      10  [emitted]  common
               app.71e5570ea286044371c3.js    39.5 kB      11  [emitted]  app
          manifest.aaf80505a99b39af859e.js    1.94 kB      12  [emitted]  manifest
                                  LICENSES  984 bytes          [emitted]
 + 16 hidden assets

ERROR in ./components/Footer.vue
Module not found: Error: Can't resolve 'stylus-loader' in '/www/xi-portals/production/source/components'
 @ ./components/Footer.vue 2:2-495
 @ ./node_modules/babel-loader/lib?{"babelrc":false,"cacheDirectory":false,"presets":["/www/xi-portals/production/source/node_modules/babel-preset-vue-app/dist/index.common.js"]}!./node_modules/vue-loader/lib/selector.js?type=script&index=0!./layouts/error.vue
 @ ./layouts/error.vue
 @ ./.nuxt/index.js
 @ ./.nuxt/client.js

ERROR in ./components/Header.vue
Module not found: Error: Can't resolve 'stylus-loader' in '/www/xi-portals/production/source/components'
 @ ./components/Header.vue 2:2-495
 @ ./node_modules/babel-loader/lib?{"babelrc":false,"cacheDirectory":false,"presets":["/www/xi-portals/production/source/node_modules/babel-preset-vue-app/dist/index.common.js"]}!./node_modules/vue-loader/lib/selector.js?type=script&index=0!./layouts/error.vue
 @ ./layouts/error.vue
 @ ./.nuxt/index.js
 @ ./.nuxt/client.js

ERROR in ./layouts/error.vue
Module not found: Error: Can't resolve 'stylus-loader' in '/www/xi-portals/production/source/layouts'
 @ ./layouts/error.vue 2:2-494
 @ ./.nuxt/index.js
 @ ./.nuxt/client.js

ERROR in ./layouts/default.vue
Module not found: Error: Can't resolve 'stylus-loader' in '/www/xi-portals/production/source/layouts'
 @ ./layouts/default.vue 2:2-496
 @ ./node_modules/babel-loader/lib?{"babelrc":false,"cacheDirectory":false,"presets":["/www/xi-portals/production/source/node_modules/babel-preset-vue-app/dist/index.common.js"]}!./node_modules/vue-loader/lib/selector.js?type=script&index=0!./.nuxt/App.vue
 @ ./.nuxt/App.vue
 @ ./.nuxt/index.js
 @ ./.nuxt/client.js

ERROR in ./pages/detail.vue
Module not found: Error: Can't resolve 'stylus-loader' in '/www/xi-portals/production/source/pages'
 @ ./pages/detail.vue 2:2-495
 @ ./.nuxt/router.js
 @ ./.nuxt/index.js
 @ ./.nuxt/client.js

ERROR in ./pages/business.vue
Module not found: Error: Can't resolve 'stylus-loader' in '/www/xi-portals/production/source/pages'
 @ ./pages/business.vue 2:2-497
 @ ./.nuxt/router.js
 @ ./.nuxt/index.js
 @ ./.nuxt/client.js

ERROR in ./pages/index.vue
Module not found: Error: Can't resolve 'stylus-loader' in '/www/xi-portals/production/source/pages'
 @ ./pages/index.vue 2:2-494
 @ ./.nuxt/router.js
 @ ./.nuxt/index.js
 @ ./.nuxt/client.js

ERROR in ./pages/breed.vue
Module not found: Error: Can't resolve 'stylus-loader' in '/www/xi-portals/production/source/pages'
 @ ./pages/breed.vue 2:2-494
 @ ./.nuxt/router.js
 @ ./.nuxt/index.js
 @ ./.nuxt/client.js

ERROR in ./pages/contact.vue
Module not found: Error: Can't resolve 'stylus-loader' in '/www/xi-portals/production/source/pages'
 @ ./pages/contact.vue 2:2-496
 @ ./.nuxt/router.js
 @ ./.nuxt/index.js
 @ ./.nuxt/client.js

ERROR in ./pages/product-list.vue
Module not found: Error: Can't resolve 'stylus-loader' in '/www/xi-portals/production/source/pages'
 @ ./pages/product-list.vue 2:2-501
 @ ./.nuxt/router.js
 @ ./.nuxt/index.js
 @ ./.nuxt/client.js

ERROR in ./pages/join.vue
Module not found: Error: Can't resolve 'stylus-loader' in '/www/xi-portals/production/source/pages'
 @ ./pages/join.vue 2:2-493
 @ ./.nuxt/router.js
 @ ./.nuxt/index.js
 @ ./.nuxt/client.js

ERROR in ./pages/question.vue
Module not found: Error: Can't resolve 'stylus-loader' in '/www/xi-portals/production/source/pages'
 @ ./pages/question.vue 2:2-497
 @ ./.nuxt/router.js
 @ ./.nuxt/index.js
 @ ./.nuxt/client.js

ERROR in ./pages/about.vue
Module not found: Error: Can't resolve 'stylus-loader' in '/www/xi-portals/production/source/pages'
 @ ./pages/about.vue 2:2-494
 @ ./.nuxt/router.js
 @ ./.nuxt/index.js
 @ ./.nuxt/client.js
Error: Webpack build exited with errors
    at /www/xi-portals/production/source/node_modules/nuxt/lib/builder/builder.js:498:27
    at emitRecords.err (/www/xi-portals/production/source/node_modules/webpack/lib/Compiler.js:269:13)
    at Compiler.emitRecords (/www/xi-portals/production/source/node_modules/webpack/lib/Compiler.js:375:38)
    at emitAssets.err (/www/xi-portals/production/source/node_modules/webpack/lib/Compiler.js:262:10)
    at applyPluginsAsyncSeries1.err (/www/xi-portals/production/source/node_modules/webpack/lib/Compiler.js:368:12)
    at next (/www/xi-portals/production/source/node_modules/tapable/lib/Tapable.js:218:11)
    at Compiler.compiler.plugin (/www/xi-portals/production/source/node_modules/webpack/lib/performance/SizeLimitsPlugin.js:99:4)
    at Compiler.applyPluginsAsyncSeries1 (/www/xi-portals/production/source/node_modules/tapable/lib/Tapable.js:222:13)
    at Compiler.afterEmit (/www/xi-portals/production/source/node_modules/webpack/lib/Compiler.js:365:9)
    at require.forEach.err (/www/xi-portals/production/source/node_modules/webpack/lib/Compiler.js:354:15)
    at /www/xi-portals/production/source/node_modules/async/dist/async.js:421:16
    at iteratorCallback (/www/xi-portals/production/source/node_modules/async/dist/async.js:998:13)
    at /www/xi-portals/production/source/node_modules/async/dist/async.js:906:16
    at /www/xi-portals/production/source/node_modules/graceful-fs/graceful-fs.js:43:10
    at FSReqWrap.oncomplete (fs.js:135:15)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! portals@1.0.0 build: `nuxt build && backpack build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the portals@1.0.0 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/dylan/.npm/_logs/2018-11-08T01_52_33_719Z-debug.log

  post-deploy hook failed

Deploy failed
1

ecosystem.json文件内容如下

{
    "apps": [
        {
            "name": "portals",
            "script": "start.js",
            "env": {
                "COMMON_VARIABLE": "true"
            },
            "env_production": {
                "NODE_ENV": "production"
            }
        }
    ],
        "deploy": {
        "production": {
            "user": "dylan",
                "host": ["116.61.128.61"],
                "port": "9527",
                "ref": "origin/master",
                "repo": "git@gitee.com:lz_dylan/xi-portals.git",
                "path": "/www/xi-portals/production",
                "ssh_options": "StrictHostKeyChecking=no",
                "post-deploy": "yarn install && npm run build && pm2 startOrRestart ecosystem.json --env production",
                "env": {
                "NODE_ENV": "production"
            }
        },
        "plus": {
            "user": "dylan",
                "host": ["116.61.128.61"],
                "port": "9527",
                "ref": "origin/master",
                "repo": "git@gitee.com:lz_dylan/xi-portals.git",
                "ssh_options": "StrictHostKeyChecking=no",
                "post-deploy": "yarn install && pm2 startOrRestart ecosystem.json --env production",
                "env": {
                "NODE_ENV": "production"
            }
        }
    }
}

写回答

1回答

Scott

2018-11-08

可以全部替换为 npm,并且 package-lock 也用 npm 重新安装 stylus-loader 保存一下,统一各个环境的包工具和包版本,看报错是模块安装缺少或者失败导致

0
0

Koa2框架从0开始构建预告片网站

Koa2+MongoDB+Parcel+Puppeteer+AntDesign快速搭建预告片网站

751 学习 · 362 问题

查看课程