-
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
ES Modules does not work with namespaced library #27408
Comments
the modules implementation currently disables extension resolution. you'll need to use |
Closing as answered. |
Had this same issue, @devsnek solution worked, thanks! |
this is sort of an ongoing feedback thing for modules team so i'm gonna re-open it cc @bnoordhuis |
@aadamsx how are you using lodash-es + experimental-modules flag on node? This
Error =>
|
Regarding
Is node or the modules loader able to see that the file is exported via commonjs.js
node12.js:
|
no, we have to declare the export names before evaluation, so we don't know what module.exports looks like. |
Have the same issue. And then when I use |
Have same issue with date-fns. Try using this syntax, works for me: |
@ench0 @TrevTheDev be careful: Try to import a |
Tried, this is my full list of imports, no issues at all:
|
@ench0 if you are using typescript (without explicitly configuring es6 modules transpiling) then your using commonjs aka require. Test is easy as creating a folder with the following:
{
"type": "module",
"dependencies": {
"date-fns": "^2.10.0"
}
}
import addDays from 'date-fns/addDays.js'
// import { addDays } from 'date-fns'; And then: yarn install
node --experimental-modules test.js First import dies with:
Second import dies with:
|
The actual path is These lookups are not enabled for ES modules. Closing as this is by design. Help ensuring this is better explained in the documentation would be very welcome as it is a very common issue. |
@guybedford, I'm trying to convert my project from CommonJS (CJS) to ES Module (MJS), to do that I use: import mysqlPromise from "mysql2/promise"; But then I get an error:
I checked this thread but although the issue is closed I can't find a solution proposal. |
@pubmikeb in ESM, you can't omit the extension for https://unpkg.com/browse/mysql2@2.1.0/promise.js so you'd need |
@guybedford I understand, but what is the intended path for all the ecosystem to move to ESM then? |
As a package consumer, just including extensions for any resolution not
governed by main or exports. And this will ensure compatibility in other JS
environments too.
…On Sat, Apr 11, 2020 at 00:23 Damiano ***@***.***> wrote:
@guybedford <https://github.com/guybedford> I understand, but what is the
intended path for all the ecosystem to move to ESM then?
Do you expect all package mantainers to add the exports field in the
package.json?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#27408 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAESFSX7V2VUDL65FJC5R3DRMALF5ANCNFSM4HILSXPQ>
.
|
@guybedford I'm not sure I understood, my bad! |
@damianobarbati in https://unpkg.com/browse/es-get-iterator@1.1.0/, i'm using the exports field combined with |
@ljharb thank you! I'll give it a try soon. |
In order for module resolution to work with .mjs or package: module code we need to utilize the conditional export feature of node. > The current specifier resolution does not support all default behavior of the CommonJS loader. One of the behavior differences is automatic resolution of file extensions and the ability to import directories that have an index file. https://nodejs.org/api/esm.html#esm_customizing_esm_specifier_resolution_algorithm https://nodejs.org/api/packages.html#packages_conditional_exports This directly enables rxjs to work with mjs code and commonjs code since mjs does not support loading bare folder paths. This is a fix to: sveltejs/kit#612 and is directly related to the conversation in this issue within node core nodejs/node#27408
In order for module resolution to work with .mjs or package: module code we need to utilize the conditional export feature of node. > The current specifier resolution does not support all default behavior of the CommonJS loader. One of the behavior differences is automatic resolution of file extensions and the ability to import directories that have an index file. https://nodejs.org/api/esm.html#esm_customizing_esm_specifier_resolution_algorithm https://nodejs.org/api/packages.html#packages_conditional_exports This directly enables rxjs to work with mjs code and commonjs code since mjs does not support loading bare folder paths. This is a fix to: sveltejs/kit#612 and is directly related to the conversation in this issue within node core nodejs/node#27408
…oading. In order for module resolution to work with .mjs or package: module code we need to utilize the conditional export feature of node. > The current specifier resolution does not support all default behavior of the CommonJS loader. One of the behavior differences is automatic resolution of file extensions and the ability to import directories that have an index file. https://nodejs.org/api/esm.html#esm_customizing_esm_specifier_resolution_algorithm https://nodejs.org/api/packages.html#packages_conditional_exports This directly enables rxjs to work with mjs code and commonjs code since mjs does not support loading bare folder paths. This is a fix to: sveltejs/kit#612 and is directly related to the conversation in this issue within node core nodejs/node#27408
…oading. (#6192) * feat(esm): Add exports within package.json to enable scoped package loading. In order for module resolution to work with .mjs or package: module code we need to utilize the conditional export feature of node. > The current specifier resolution does not support all default behavior of the CommonJS loader. One of the behavior differences is automatic resolution of file extensions and the ability to import directories that have an index file. https://nodejs.org/api/esm.html#esm_customizing_esm_specifier_resolution_algorithm https://nodejs.org/api/packages.html#packages_conditional_exports This directly enables rxjs to work with mjs code and commonjs code since mjs does not support loading bare folder paths. This is a fix to: sveltejs/kit#612 and is directly related to the conversation in this issue within node core nodejs/node#27408 * feat(esm): Add test case for esm imports. Context: sveltejs/kit#612 nodejs/node#27408
Maybe this will help my esm imports? Notes: - SO Discussion: https://stackoverflow.com/a/65588027 - GH Discussion: nodejs/node#27408 (comment)
HOPEFULLY CI WORKS!!!!! * Highlight features in README more * Use `--es-module-specifier-resolution=node` Maybe this will help my esm imports? Notes: - SO Discussion: https://stackoverflow.com/a/65588027 - GH Discussion: nodejs/node#27408 (comment) * Delete unused imports * use `npm run start` in dockerfile * Delete `node-canvas` imports those were only for arm, and i only installed them to test stuff on my own machine
I'm using
experimental-modules
since v8. I tried to use"type": "module"
in v12 and it's fine except for namespaced library (uuid, lodash, ...)This kind of imports:
Causes this error:
The text was updated successfully, but these errors were encountered: