Quantcast
Channel: Omit the file extension, ES6 module NodeJS - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Omit the file extension, ES6 module NodeJS

$
0
0

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.

  1. 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.
  2. 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?


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images