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

Philip Feldmann
  • 7,887
  • 6
  • 41
  • 65

1 Answers1

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"]
}
zr0gravity7
  • 2,917
  • 1
  • 12
  • 33
Roberto Alicata
  • 516
  • 6
  • 7
  • Is [`plugin-proposal-object-rest-spread`](https://babeljs.io/docs/en/babel-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`](https://github.com/babel/babel/blob/master/packages/babel-preset-env/src/available-plugins.js#L78)? – zr0gravity7 Aug 23 '21 at 01:35
  • ^ Nevermind, I see this was updated 2 years ago (by Robin Wieruch, cool to see him here). Will update reference link text and address. – zr0gravity7 Aug 23 '21 at 01:37
  • NOTE: This plugin is included in @babel/preset-env, in ES2018 so the plugin is not needed. – Victor Shelepen Jun 03 '22 at 12:44