question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to get this to work with ES6 babel-node

See original GitHub issue

I realize that the README describes a node-dev.json file to set extension settings, but it is not clear to me how to get this to work with babel-node. Currently I’m running my server.js code with the command ./node_modules/.bin/babel-node server/. When I run the command with node-dev, node-dev server, I get the error Unexpected token import. My node-dev.json file is like so:

{
  "extensions": {
    "js": {
      "name": "babel/register"
    }
  }
}

Any suggestions would be very welcome!

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
amosyuencommented, Oct 12, 2017

After some playing around, looks like instead of requiringbabel-register setting this in my .node-dev.json did the trick:

{
  "extensions": {
    "js": {
      "name": "babel-core/register"
    }
  }
}
0reactions
kenberkeleycommented, Nov 29, 2017

In addition to @amosyuen 's .node-dev.json, you might need a .babelrc in the same directory:

{
  "presets": ["stage-2"]
}

P.S. modules: false will lead to SyntaxError: Unexpected token import, so remove it!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Write ES6 in Node using Babel - DEV Community ‍ ‍
Hi all In this short article, Today we will be learning about How to use ES6 syntax(like import from, export default, etc..) with...
Read more >
babel/node - Babel.js
babel -node is a CLI that works exactly the same as the Node.js CLI, with the added benefit of compiling with Babel presets...
Read more >
How to Setup Babel in Node.js - freeCodeCamp
Let's setup a basic Node app which we will use for this tutorial. Create a new folder. For this tutorial, I'll call mine...
Read more >
Writing ES6 in NodeJS using Babel | by Makinde Abass
Babel is a toolchain that is mainly used to convert ECMAScript 2015+ code into a backwards compatible version of JavaScript in current and...
Read more >
Using ES6 with BABEL in Node.js - LinkedIn
Before getting started, let me clear Node.js provides support for almost all the ES6 features since Node.js v6 update.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found