2

I'm getting the following error trying us the es6 import syntax inside the node console.

import Dog from  './lib/Dog.js';
Thrown:
import Dog from  './lib/Dog.js';
^^^^^^

SyntaxError: Cannot use import statement outside a module

I'm initiating the console as follows:

$ node --experimental-modules
Welcome to Node.js v12.13.0.
Type ".help" for more information.
> (node:81053) ExperimentalWarning: The ESM module loader is experimental.

You can see that I'm running node 12.13 and using the --experimental-modules flag.

My package.json also includes {"type": "module"}

but for some reason it still won't let me use the import syntax.

Any ideas are much appreciated.

Jeff
  • 3,943
  • 8
  • 45
  • 68
  • 1
    Does this answer your question? [How to import an ES module in Node.js REPL?](https://stackoverflow.com/questions/54784608/how-to-import-an-es-module-in-node-js-repl) – FZs Feb 13 '20 at 14:33

0 Answers0