I am building a react app from scratch with yarn
and not npm
as yarn is fast than npm. I am not using create-react-app
command to create my react app just to make sure I do everything from scratch.
I have a webpack file with basic configuration snippet copied from webpack site.
Please see I am using babel-node
to run my project, as I have ES6 import
in my node server.js
file.
In below file, to tell pm2
to use babel-node
instead of regular node
, interpreter is used
{
"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
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
Note: please see, I am adding my packages using yarn add --dev
command
Question: I am receiving spawn babel-node ENOENT
error. How can I make sure I don't run into this.
I solved this finally with the help of link
I have to install babel-cli
globally to make pm2 run the babel-node properly..