PM2 解释器未将 babel 用于我的反应应用程序开发环境



我正在尝试为我的开发服务器设置 pm2,它似乎启动了,但在端口 3000 中访问我的站点时,它说无法访问它拒绝连接。我检查了我的pm2日志,它说

语法错误:/var/www/html/ucdirectorapp/src/index.js: 意外令牌 (33:4) 0|UC导演开发 | 31 | ReactDOM.render( 0|UC导演开发 | 32 | 0|UC导演开发 |> 33 | 0|UC导演开发 | | ^ 0|UC导演开发 | 34 | , document.getElementById('root')); 0|UC导演开发 | 35 |

所以我认为这与我的口译员有关。

我已经编译并制作了一个构建文件夹。

我已经将解释器指向./node_modules/@babel/cli/bin/babel.js 甚至 ./node_modules/babel-cli/bin/babel-node.js。

我试过重新安装 babel-cli。我尝试删除我的node_modules并重新安装所有内容。

我尝试在全球范围内安装 babel-cli。


//this is my pm2 config file
module.exports = {
apps: [{
name: "ucdirectorapp",
script: "./src/index.js",
watch: [
"./build",
"./public",
"./src"
],
watch_delay: 1000,
ignore_watch: ["node_modules"],
watch_options: {
"followSymlinks": false
},
env: {
name: 'ucdirector-dev',
NODE_ENV: 'development',
"PORT": 3000,
},
interpreter: "./node_modules/babel-cli/bin/babel.js"
}],
};
--
//my webpack config uses these presets and plugins for js
test: /.(js|jsx)$/,
use: [
{
loader: "babel-loader",
options: {
presets:[ "@babel/preset-env", "@babel/preset-react"],
plugins: [
"@babel/plugin-syntax-dynamic-import", '@babel/plugin-proposal-class-properties'
]
}
}
],

---
//in my package.json these are the dependecies i'm using for babel 
"@babel/plugin-proposal-class-properties": "^7.4.4",
"babel-plugin-async-to-promises": "^1.0.5",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-env": "^1.7.0",
"babel-preset-react": "^6.24.1"
//this is what i have in dev dependecies
"@babel/core": "^7.4.5",
"@babel/plugin-transform-runtime": "^7.4.4",
"@babel/preset-env": "^7.4.5",
"@babel/preset-react": "^7.0.0",
"babel-core": "^6.26.3",
"babel-loader": "^8.0.6",
"babel-polyfill": "^6.26.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-stage-0": "^6.24.1",

//and this is the script that I am using 
"pm": "pm2 start config/server/pm2.config.js --watch",

我希望该站点在端口 3000 上启动,并删除语法错误。但是我看到了这个语法错误。我猜它没有重新识别反应类。

语法错误:/var/www/html/ucdirectorapp/src/index.js: 意外令牌 (33:4) 0|UC导演开发 | 31 | ReactDOM.render( 0|UC导演开发 | 32 | 0|UC导演开发 |> 33 | 0|UC导演开发 | | ^ 0|UC导演开发 | 34 | , document.getElementById('root'));

我发现 ecosystem.config.js 可以使用解释器 ./node_modules/.bin/babel-node,但在他们的文档中说,只有当它运行在:

">分叉"模式

请记住,这些命令仅适用于fork_mode。如果要运行PM2集群,请参阅下面的替代方案。

您可以查看其页面中的所有信息。

http://pm2.keymetrics.io/docs/tutorials/using-transpilers-with-pm2#babel

最新更新