fix: import yargs/yargs in esm projects#2151
Merged
bcoe merged 4 commits intoyargs:mainfrom May 11, 2022
Merged
Conversation
3 tasks
Member
Contributor
Author
|
This is already happening with Node.js >= 12 as far as I can see. The The failing test is running a ESM project with this package.json: {
"name": "bandersnatch-smoke-test-esm",
"type": "module",
"scripts": {
"test": "node index.mjs"
},
"dependencies": {
"bandersnatch": "^1.9.2"
}
}
import createYargs from 'yargs/yargs'; |
Contributor
Author
|
@bcoe Is there anything I can do to help this get merged? I could add a simple smoke test (like in the |
bcoe
approved these changes
May 11, 2022
Member
|
@hongaar thank you for the patch, hopefully it does the trick for you. |
hongaar
added a commit
to hongaar/yargs
that referenced
this pull request
May 12, 2022
Due to the `yargs.mjs` file not being published, the fix merged with yargs#2151 is not effective yet. This change should fix that. ``` Cannot find module './node_modules/yargs/yargs.mjs' imported from ./cli.js ```
This was referenced May 12, 2022
Contributor
Author
5 tasks
This was referenced Sep 6, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When using
import yargs from "yargs/yargs"in an ESM project ("type": "module"in package.json), Node.js will throw this error:To solve this, add a new
yargs.mjsfile and update the./yargsexport in the package.json.Confirmed that this works for a simple ESM project where
yargsis a transitive dependency: hongaar/bandersnatch#392 (intests/smoke/esm)Related to #2014