I'm trying to get a handle on Node and ES modules. Specifically how/if you can omit the file extension from the path string value of the import statement (and optionally get VSCode to autocomplete those paths).
I understand you can either gives files the .mjs
extension or set "type" = "modules"
in the package.json
but both approaches lead to the following problems.
- VSCode won't autocomplete the path if the file extension is
.mjs
, it only sees the file if it's .js
. However if it is .js
the autocomplete omits the extension from the string and the import fails until I add it manually.
- Trying to use a library like
graphql
inside my own modules also fails because all the import statements between the .mjs
files in the graphql module have been written omitting the extension from the string.
SO... when is not including the extension valid with ES6 module imports, and is there anyway to get this condition enabled with NodeJS?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…