What’s New in Node.js 12: ESM Imports

Hello, Imports

{ "type": "module" }
node --experimental-modules index.js (node:7289) ExperimentalWarning: The ESM module loader is experimental. Hello, world!
$ node index.js /index.js:1 import test from './test.js'; ^^^^ SyntaxError: Unexpected identifier
$ rm package.json $ node --experimental-modules index.js (node:9089) ExperimentalWarning: The ESM module loader is experimental. /index.js:1 import test from './test.js'; ^^^^ SyntaxError: Unexpected identifier
$ node --experimental-modules index.mjs (node:10191) ExperimentalWarning: The ESM module loader is experimental. Hello, world!
$ node --experimental-modules . (node:10296) ExperimentalWarning: The ESM module loader is experimental. internal/modules/esm/default_resolve.js:69 let url = moduleWrapResolve(specifier, parentURL); ^ Error: Cannot find module '/' imported from /

Importing CommonJS npm Modules

import mongoose from 'mongoose'; console.log(mongoose.version);

Moving On

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store