[英]spawn babel-node ENOENT
I am building a react app from scratch with yarn
and not npm
as yarn is fast than npm. 我正在从头开始用yarn
而不是npm
建造一个反应应用,因为纱线比npm快。 I am not using create-react-app
command to create my react app just to make sure I do everything from scratch. 我没有使用create-react-app
命令创建我的反应应用程序,只是为了确保我从头开始做所有事情。
I have a webpack file with basic configuration snippet copied from webpack site . 我有一个webpack文件,其中包含从webpack站点复制的基本配置代码段。
Please see I am using babel-node
to run my project, as I have ES6 import
in my node server.js
file. 请参阅我使用babel-node
来运行我的项目,因为我在节点server.js
文件中import
了ES6。
In below file, to tell pm2
to use babel-node
instead of regular node
, interpreter is used 在下面的文件中,告诉pm2
使用babel-node
而不是常规node
,使用解释器
{
"name": "advanced-react",
"version": "1.0.0",
"main": "lib/server.js",
"author": "GopiGorantala",
"license": "MIT",
"scripts": {
"dev": "pm2 start lib/server.js --watch --interpreter babel-node"
},
"babel": {
"presets": [
"react",
"env",
"stage-2"
]
},
"devDependencies": {
"babel-eslint": "^10.0.1",
"eslint": "^5.13.0",
"eslint-plugin-react": "^7.12.4"
},
"dependencies": {
"babel-preset-env": "^1.7.0",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-2": "^6.24.1",
"ejs": "^2.6.1",
"express": "^4.16.4",
"pm2": "^3.2.9"
}
}
import express from 'express';
import config from './config';
const app = express();
app.use(express.static('public'));
app.set('view engine', 'ejs');
app.get('/', (req, res) => {
res.render('index', {answer: 42});
});
app.listen(config.port, function listenHandler() {
console.info(`running on ${config.port}`);
});
when i run my application with yarn dev
, I don't get the server as online but instead I get as errored
当我使用yarn dev
运行我的应用程序时,我没有将服务器作为在线,而是我得到了errored
I tried to check the logs with yarn pm2 logs
to check on the error but I don't get much information.. Please see screenshot below 我试图用yarn pm2 logs
,但我没有得到太多信息..请参阅下面的截图
Note: please see, I am adding my packages using yarn add --dev
command 注意:请参阅,我使用yarn add --dev
命令添加我的包
Question: I am receiving spawn babel-node ENOENT
error. 问题:我收到了spawn babel-node ENOENT
错误。 How can I make sure I don't run into this. 我怎样才能确保我不碰到这个。
Not all webpack configs work with jsx. 并非所有webpack配置都适用于jsx。 WP should look something like this. WP应该看起来像这样。
module.exports = {
entry: './src/index.js',
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: ['babel-loader']
}
]
},
resolve: {
extensions: ['*', '.js', '.jsx']
},
output: {
path: __dirname + '/dist',
publicPath: '/',
filename: 'bundle.js'
},
devServer: {
contentBase: './dist'
}
};
If you are using latest babel(^7.0.0) you should install 'babel-node' this way: 如果您使用的是最新的babel(^ 7.0.0),您应该以这种方式安装'babel-node':
sudo npm i -g @babel/node
Do not install via this way, because it will work only for babel 6: 不要通过这种方式安装,因为它只适用于babel 6:
npm install -g babel-cli
Documentation looks outdated and suitable for babel 6 version. 文档看起来过时,适合babel 6版本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.