reactjs - PM2 解释器没有在我的开发环境中使用 babel 来响应应用程序
问题描述
我正在尝试为我的开发服务器设置 pm2,它似乎已启动,但在访问我的端口 3000 的站点时,它说无法访问拒绝连接。我检查了我的 pm2 日志,它说
语法错误:/var/www/html/ucdirectorapp/src/index.js:意外令牌 (33:4) 0|ucdirector-dev | 31 | ReactDOM.render( 0|ucdirector-dev | 32 | 0|ucdirector-dev | > 33 | 0|ucdirector-dev | | ^ 0|ucdirector-dev | 34 | , document.getElementById('root')); 0|ucdirector-dev | 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|ucdirector-dev | 31 | ReactDOM.render( 0|ucdirector-dev | 32 | 0|ucdirector-dev | > 33 | 0|ucdirector-dev | | ^ 0|ucdirector-dev | 34 | , document.getElementById('root'));
解决方案
我发现生态系统.config.js 可以使用解释器 ./node_modules/.bin/babel-node 但在他们的文档中说只有当它运行在:
“分叉”模式
请记住,这些命令仅适用于 fork_mode。如果您想运行 PM2 集群,请参考下面的替代方案。
您可以查看他们页面中的所有信息。
http://pm2.keymetrics.io/docs/tutorials/using-transpilers-with-pm2#babel
推荐阅读
- javascript - 如何使用 twilio 在聊天程序中附加名称和消息?
- angular - 为什么 GET 工作,但 DELETE 和 POST 在 Angular 2 中不起作用(错误:404)?
- javascript - 针对已编译的包运行测试
- android-studio - 初始化 gradle 未在颤振应用程序中完成
- javascript - Whatsapp 重定向链接,如 wa.me,但具有自定义域
- swift - 如何以编程方式更改紧凑尺寸类?
- algorithm - What's the difference between Modified Dijkstra with single source, single destination point and Uniform Cost Search?
- php - Xampp 安装期间 Php.exe 安装失败
- c# - 在 DevExpress PivotGridControl 中使用 DisplayNameAttribute
- python - 具有特定重复的元素数组的 Python 排列