Reputation: 8868
I'm using node version 14
Here's my package.json file:
{
"scripts": {
"start": "nodemon --exec babel-node ./src/app.js",
"build": "babel ./src -s -d dist",
},
"devDependencies": {
"@babel/core": "^7.10.3",
"@babel/node": "^7.10.3",
"@babel/preset-env": "^7.10.3",
"nodemon": "^2.0.4"
}
}
and here's babel.config.json file:
{
"presets": ["@babel/preset-env"]
}
Now I guess that "@babel/preset-env"
allows us to use the latest JavaScript.
When I run npm start
everything works OK.
But if i run npm run build
i got the following error:
SyntaxError: src/api/review/controller.js: Unexpected token (8:25)
6 |
7 | module.exports.create = asyncHandler(async (req, res, next) => {
> 8 | const reviewData = { ...req.body, user: req.user._id };
| ^
9 | const review = await Review.create(reviewData);
10 | response.build(res, review, 201);
11 | });
I added a new plugin to make it work "@babel/plugin-proposal-object-rest-spread": "^7.10.4"
and here's babel.config.json file:
{
"presets": ["@babel/preset-env"],
"plugins": ["@babel/plugin-proposal-object-rest-spread"]
}
But I didn't work
Upvotes: 1
Views: 1148
Reputation: 8868
Problem solved by adding the following package: "@babel/cli": "^7.10.4"
Upvotes: 1
Reputation: 1995
Install
npm install --save-dev @babel/plugin-proposal-object-rest-spread
then change your .babelrc file:
{
"presets": ["@babel/preset-env"],
"plugins": ["@babel/plugin-proposal-object-rest-spread"]
}
Upvotes: 0