Using the import state in Node v14+ without adding the .js extension

Viewed 182

In Node v12 I was using ESM imports by adding the following flags:

node --experimental-modules --experimental-json-modules --es-module-specifier-resolution=node index.js

This let me do the following:

import myFunc from "./lib/myFunc"

Now, in Node v14, we apparently no longer need the experimental-modules flag. However, when I run node index.js I get an error telling me that my imports need to .js extension like this:

import myFunc from "./lib/myFunc.js"

Is this the intended behaviour? If so, why have they suddenly added the need for the .js extension when previously it wasn't. The exact error I get is:

Cannot find module 'c:\xxx\lib\myFunc' imported from c:\xxx\index.js
Did you mean to import ../lib/myFunc.js?
0 Answers
Related