Babel-node doesn't transform spread operator on preset env
Asked Answered
G

1

24

I'm trying to use babel-node with nodemon for the hot-reloading. I've basically followed this repo.

My dev script in package.json looks like that:

"dev": "nodemon app.js --exec babel-node --presets env"

My .babelrc:

{
  "presets": ["env"]
}

Even though the spread operator is listed as supported by the env preset, when using it with this setup I get a

SyntaxError: Unexpected token

Gargan answered 15/3, 2018 at 14:6 Comment(2)
What is your babel-cli version?Jellybean
Mind to paste the code?Hegemony
N
44

Install plugin-proposal-object-rest-spread.

npm install --save-dev @babel/core @babel/plugin-proposal-object-rest-spread

then change your .babelrc file:

{
  "presets": ["@babel/preset-env"],
  "plugins": ["@babel/plugin-proposal-object-rest-spread"]
}
Nicety answered 20/3, 2018 at 11:44 Comment(3)
Is plugin-proposal-object-rest-spread now preferred, given that plugin-proposal-object-rest-spread has not been updated in 4 years, and that the former is now mentioned on the babel registry, and included in @babel/preset-env (see available-plugins.js?Macron
^ Nevermind, I see this was updated 2 years ago (by Robin Wieruch, cool to see him here). Will update reference link text and address.Macron
NOTE: This plugin is included in @babel/preset-env, in ES2018 so the plugin is not needed.Gordon

© 2022 - 2024 — McMap. All rights reserved.