-
Notifications
You must be signed in to change notification settings - Fork 29.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
doc: confusing support for extensionless ESM #30655
Comments
Ah I forgot about |
It seems that is documented at that page, see: https://nodejs.org/api/esm.html#esm_code_package_json_code_code_type_code_field. |
It's documented at the very bottom of the page. Maybe update the example to say something like this? I feel like a lot of people are (like me!) going to run into this when switching to the native ESM loader. // my-app.js, part of the same example as above
import './startup.js'; // Loaded as ES module because of package.json
+
+// Requires --es-module-specifier-resolution=node
+import './startup'; // Loaded as ES module because of package.json |
Commented in the PR TL;DR extensionless filepath and specifier
filepath with extension and extensionless specifier
|
I have an extensionless file (which is an executable) failing to be imported, despite λ JG (master): cat ./test.mjs
#!/usr/bin/env node
import "./bin/list";
λ JG (master): head bin/list
#!/usr/bin/env node
import {join, resolve} from "path";
…
λ JG (master): ./test.mjs
(node:4311) ExperimentalWarning: The ESM module loader is experimental.
internal/modules/run_main.js:50
internalBinding('errors').triggerUncaughtException(
^
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension: /Users/john/Labs/JG/bin/list
at Loader.resolve [as _resolve] (internal/modules/esm/default_resolve.js:114:13)
at Loader.resolve (internal/modules/esm/loader.js:74:33)
at Loader.getModuleJob (internal/modules/esm/loader.js:148:40)
at ModuleWrap.<anonymous> (internal/modules/esm/module_job.js:41:40)
at link (internal/modules/esm/module_job.js:40:36) {
code: 'ERR_UNKNOWN_FILE_EXTENSION'
} This happens both with static and dynamic imports. Current Node version: v13.2.0 |
From the ESM docs (emphasis mine):
Unless I am mistaken (discussed in nodejs/modules#443), extensionless module resolution is not currently supported.
How can you have an
import
statement for an extensionless file when it does not resolve?The text was updated successfully, but these errors were encountered: