Answer the question
In order to leave comments, you need to log in
How to import a JS module without specifying an extension?
In other people's code for Node.js, I often see how JS modules are imported without specifying the extension .js
, for example:
import Example from './example'; // вместо './example.js'
Answer the question
In order to leave comments, you need to log in
In pure Node.js, when using ESM, it is mandatory to specify the extension due to following the specification. If you want to use ESM, but not depend on pure Node.js, you need to use one of several options:
Read documentation. It's very good in webpack.
https://webpack.js.org/configuration/resolve/#reso...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question