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
Webpack building broken #1754
Comments
@dl748 yargs now fully supports ESM, so in some cases there should be no need to WebPack. There's now an example of how to get things running in the browser in the I think perhaps you just need to webpack the |
@dl748 may I ask why you're using yargs in the browser? as I took on the work to make this possible, one question I had was whether it would actually benefit many people. |
I'm not using a browser as you can see with my configuration. "target: 'node'". I generally use webpack to compile a typescript app to a single standalone app (.js file) so that i can run it on a machine that has node but can't install anything from a repository. webpack will pull in the node_modules (except for binary specific, which i don't use) I just created a simple (non typescript) example that also failed. |
I also use webpack on my nodeJs services. It keeps the clutter down and allows for quickly updating containers while troubleshooting issues inside of clusters. |
@dl748 @ Michael-Tajmajer-Bentley I suggest opening an issue on Webpack too, and I'll happily take a patch to our docs. My reasoning being that ESM should certainly be easily Webpacked, and I'm surprised that Webpack isn't properly consuming ESM modules. |
fwiw ncc may be more suitable for this use-case. or even rollup. I can't imagine the |
@boneskull |
Ok, looks like yargs is a little broken..
So when webpack is import yargs, it imports the "modules" of both y18n and yargs-parser, but then loads the cjs of yargs which is expecting the modules to be imported a completely different way. |
In my opinion yargs isn't broken, Webpack is not properly resolving ESM and CJS dependencies (as #6719 indicates). I think we should just document how to workaround this. |
according the package.json of yargs, there is no module to load as
this file doesn't exist so loading falls back to
|
I think I'd rather just document how to create a CJS bundle for the time being. And, when Webpack 5 solves this problem I'm happy to document an alternative approach. |
@dl748 oh, that certainly does sound like a bug. Can we simplify our configuration if that's fixed? I guess if that's fixed, things will start working once that |
I think you meant to have it
thats what i used to fix the initial issue. |
when running webpack
which at least LOOKS correct as its now loading the index.mjs now |
found a quick fix, could break some builds... webpack.config.js
This will force all modules to use the main or in yargs case, the commonjs build, instead of the module ones. |
#1759 <-- the main issue should be fixed. |
@dl748 I landed documentation for |
This is a temporary measure to fix yargs/yargs#1754. Webpack 5 would supposedly fix it properly.
Upgraded from 15.4.1 to 16.0.3 and now all my scripts built with webpack now fail with the error.
Everything seems to compile, but when i run the resulted js file, I get
TypeError: y18n is not a function
yargs/lib/platform-shims/cjs.ts
Line 40 in eb2b29d
If i modify the exported code to use
y18n.y18n(
then it works... also I needed to change allshim$1.Parser
toshim$1.Parser.default
simple webpack.config.js // works in 15.4.1
index.js
webpack@4.44.1 with yargs@15.4.1 works
webpack@4.44.1 with yargs@16.0.3 compiles but fails to run
Note: I was able to get it to work via some strange settings
I had to explicitly tell webpack to import y18n and yargs-parser via commonjs2 methods.
The text was updated successfully, but these errors were encountered: