无法使用npx babel运行pm2?

问题描述

我有一个Node.js应用,可以完美地与以下命令配合使用:

npx babel-node dist/index.js

但是,我无法在pm2上运行它。当我执行以下操作时:

pm2 start --interpreter npx babel-node dist/index.js

显然,这不起作用。当我尝试时:

pm2 start --interpreter babel-node dist/index.js

这也不起作用,因为我的全局Babel是版本6.26.3,而我的项目Babel是{​​{1}}。

是否有办法使pm2与npx配合使用,或者有办法将系统范围的babel升级7.0.0-0

解决方法

要解决此问题,您需要在methods: { setData(response){ console.log(response) // here you have the response and access to this. so you can fill the table with the data here } } 中创建一个build和一个start脚本:

package.json

然后使用开始选项运行pm2:

"scripts": {
  "build": "npx babel src -d dist","start": "npm run build && node dist/index.js"
},