无法通过pm2启动nuxt项目

时间:2019-06-30 13:41:00

标签: npm pm2 vue-cli-3 nuxt

我一直无法通过pm2启动nuxt项目。

我今天使用npx create-nuxt-app arif-app创建了一个项目,我的项目结构最初是出于测试目的,但我仍然想说明-

arif-app (project-dir) -->
    .editorconfig
    .gitignore
    .nuxt                   <DIR>
    assets                  <DIR>
    components              <DIR>
    ecosystem.config.js
    layouts                 <DIR>
    middleware              <DIR>
    node_modules            <DIR>
    nuxt.config.js
    package-lock.json
    package.json
    pages                   <DIR>
    plugins                 <DIR>
    README.md
    static                  <DIR>
    store                   <DIR>
ecosystem.config.js中的

pm2生态系统配置为-

module.exports = {
  apps : [{
    name: '.nuxt',
    script: 'index.js',

    // Options reference: https://pm2.io/doc/en/runtime/reference/ecosystem-file/
    args: 'one two',
    instances: 1,
    autorestart: true,
    watch: false,
    max_memory_restart: '1G',
    env: {
      NODE_ENV: 'development'
    },
    env_production: {
      NODE_ENV: 'production'
    }
  }],

  deploy : {
    production : {
      user : 'momustafa',
      host : '127.0.0.1',
      ref  : 'origin/master',
      repo : 'git@github.com:repo.git',
      path : 'C:\Users\momustafa\Desktop\Assets\new_test\arif-app',
      'post-deploy' : 'npm install && pm2 reload ecosystem.config.js --env production'
    }
  }
};

在package.json中是:

"scripts": {
    "dev": "nuxt",
    "build": "nuxt build",
    "start": "pm2 start ./node_modules/nuxt/bin/nuxt -i max --attach",
    "generate": "nuxt generate"
  },
  "dependencies": {
    "@nuxtjs/axios": "^5.3.6",
    "nuxt": "^2.0.0",
    "vue": "^2.6.10",
    "vue-awesome": "^3.5.4",
    "vue-loader": "^15.7.0"
  },

在pm2开始之前,我已经使用npm run build构建了项目,

现在,在构建之后,我通过pm2传递了以下命令来运行nuxt项目,

C:\Users\momustafa\Desktop\Assets\new_test\arif-app>pm2 start .nuxt
[PM2] Applying action restartProcessId on app [.nuxt](ids: 0)
[PM2] [.nuxt](0) ✓
[PM2] Process successfully started
┌──────────┬────┬─────────┬──────┬───────┬─────────┬─────────┬────────┬─────┬────────┬───────────┬──────────┐
│ App name │ id │ version │ mode │ pid   │ status  │ restart │ uptime │ cpu │ mem    │ user      │ watching │
├──────────┼────┼─────────┼──────┼───────┼─────────┼─────────┼────────┼─────┼────────┼───────────┼──────────┤
│ .nuxt    │ 0  │ N/A     │ fork │ 11164 │ stopped │ 16      │ 0      │ 0%  │ 0 B    │ momustafa │ disabled │
└──────────┴────┴─────────┴──────┴───────┴─────────┴─────────┴────────┴─────┴────────┴───────────┴──────────┘
 Use `pm2 show <id|name>` to get more details about an app

C:\Users\momustafa\Desktop\Assets\new_test\arif-app>pm2 kill
[PM2] [v] Modules Stopped
[PM2] Applying action deleteProcessId on app [all](ids: 0)
[PM2] [.nuxt](0) ✓
[PM2] [v] All Applications Stopped
[PM2] [v] PM2 Daemon Stopped

C:\Users\momustafa\Desktop\Assets\new_test\arif-app>pm2 start npm --name .nuxt -- start
[PM2] Spawning PM2 daemon with pm2_home=C:\Users\momustafa\.pm2
[PM2] PM2 Successfully daemonized
[PM2] Starting C:\PROGRAM FILES\NODEJS\NPM.CMD in fork_mode (1 instance)
[PM2] Done.
┌──────────┬────┬─────────┬──────┬──────┬─────────┬─────────┬────────┬─────┬────────┬───────────┬──────────┐
│ App name │ id │ version │ mode │ pid  │ status  │ restart │ uptime │ cpu │ mem    │ user      │ watching │
├──────────┼────┼─────────┼──────┼──────┼─────────┼─────────┼────────┼─────┼────────┼───────────┼──────────┤
│ .nuxt    │ 0  │ N/A     │ fork │ 8864 │ stopped │ 1       │ 0      │ 0%  │ 0 B    │ momustafa │ disabled │
└──────────┴────┴─────────┴──────┴──────┴─────────┴─────────┴────────┴─────┴────────┴───────────┴──────────┘
 Use `pm2 show <id|name>` to get more details about an app

而且我一直在关注pm2错误日志-

C:\Users\momustafa\Desktop\Assets\new_test\arif-app\.nuxt\index.js:1
(function (exports, require, module, __filename, __dirname) { import Vue from 'vue'
                                                                     ^^^

SyntaxError: Unexpected identifier
    at new Script (vm.js:80:7)
    at createScript (vm.js:274:10)
    at Object.runInThisContext (vm.js:326:10)
    at Module._compile (internal/modules/cjs/loader.js:664:28)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
    at Module.load (internal/modules/cjs/loader.js:600:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
    at Function.Module._load (internal/modules/cjs/loader.js:531:3)
    at Object.<anonymous> (C:\Users\momustafa\AppData\Roaming\npm\node_modules\pm2\lib\ProcessContainerFork.js:27:21)
    at Module._compile (internal/modules/cjs/loader.js:701:30)

请帮助某人。

注意:In nuxt@2.8.1的模块文件名为nuxt.js而不是nuxt-start.js

0 个答案:

没有答案