0

I want to use "import" in nodejs + express app.

I know that nodejs v6 support es6.

But I can't use "import" in my nodejs app.

Node give me This message. => SyntaxError: Unexpected token import

What can i do for es6.

Jong-Hyen Kim
  • 765
  • 2
  • 6
  • 18
  • https://stackoverflow.com/questions/36901147/es2015-import-not-working-in-node-v6-0-0-with-with-harmony-modules-option – kite.js.org Sep 14 '17 at 02:44

2 Answers2

3

The short answer: if you are using node < 8.5 you can't.

If you want to use ES modules, either use a newer version of node or use Babel or a library like @std/esm.

Nick Tomlin
  • 28,402
  • 11
  • 61
  • 90
2

Node.js 6 does not support ESModules, only CommonJS modules. You can still use ESmodules but you will need to install Babel and transpile your code.

  • Hi [fernando](https://stackoverflow.com/users/7643589/fernando-poumi%c3%a1n), Could you pls explain a bit more on detail how can Babel be used? I'm a javascript novice, and I'd appreciate your help. Thanks! – Orco Sep 06 '19 at 21:18