无法使用Babel-Node作为解释器运行PM2

2ic8powd  于 2022-10-04  发布在  Babel
关注(0)|答案(1)|浏览(248)

我试了医生里的所有方法,但似乎都不管用。当我设法用babel-node运行解释程序时,出现以下错误uncaughtException: process.send is not a function

在以下配置下,解释器无法正常工作:

ECOystem.config.js

module.exports = [{
script: './app.js',
ignore_watch:[
  "node_modules",
  "docker"
],
name: 'tower-defense',
interpreter: 'node_modules/@babel/node/bin/babel-node.js',
watch: true,
max_memory_restart: "150M",
error_file: 'logs/error.log',
out_file: 'logs/output.log',
wait_ready: true,
listen_timeout: 10000,
}, {
  script: './app.js',
  name: 'Tower Defense'
}]

我也试过用

pm2-runtime start --watch --interpreter babel-node ecosystem.config.js app.js

pm2-runtime start ecosystem.config.js --watch --interpreter babel-node app.js

pm2-runtime start ecosystem.config.js --watch --interpreter ./node_modules/@babel/node/bin/babel-node.js app.js

还有更多的变种,但似乎都不起作用。我总是收到以下错误:

import Application from './core/application';
^^^^^^

SyntaxError: Cannot use import statement outside a module

当我最终让它工作时,它是这样的:

"scripts": {
    "dev": "pm2-runtime start npm -- run test ecosystem.config.js",
    "test": "babel-node app.js"
},

但是,我得到了以下错误:

uncaughtException: process.send is not a function

只是看起来什么都不管用。如果有人能给我解释如何正确地做这件事,我将不胜感激。

我为该过程设置的坞站:

Dockerfile

FROM node:latest

WORKDIR /var/www/tower-defense
COPY . /var/www/tower-defense

RUN npm install -g babel-cli && npm install pm2 -g && npm install
CMD ["npm", "run", "dev"]

EXPOSE 4000
e1xvtsh3

e1xvtsh31#

我已经设法让它与

FROM node:latest

WORKDIR /var/www/tower-defense
COPY . /var/www/tower-defense

RUN npm install -g @babel/cli && npm install pm2 -g && npm install
CMD ["pm2-runtime", "ecosystem.config.js", "app.js"]

EXPOSE 4000

和以下配置

module.exports = [{
    script: './app.js',
    ignore_watch: [
      "node_modules",
      "docker",
      "logs",
      ".history"
    ],
    exec_interpreter: '/var/www/tower-defense/node_modules/@babel/node/bin/babel-node.js',
    name: 'tower-defense',
    watch: true,
    max_memory_restart: "150M",
    error_file: 'logs/error.log',
    out_file: 'logs/output.log',
    wait_ready: true,
    listen_timeout: 10000,
    name: 'Tower Defense'
}]

相关问题