Webpack building broken
See original GitHub issueUpgraded 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
If i modify the exported code to use y18n.y18n(
then it works… also I needed to change all shim$1.Parser
to shim$1.Parser.default
simple webpack.config.js // works in 15.4.1
var path = require('path');
module.exports = async (env, argv) => {
let config = {
mode: "development",
entry: {
"test": "./index.js",
},
output: {
path: path.resolve(__dirname, "dist")
},
target: 'node',
devtool: "source-map-inline",
};
return config;
}
index.js
var yargs = require('yargs');
console.log(yargs.argv);
webpack@4.44.1 with yargs@15.4.1 works
$ node dist/test.js
{ _: [], '$0': 'dist/test.js' }
webpack@4.44.1 with yargs@16.0.3 compiles but fails to run
$ node dist/test.js
dist/test.js:5012
y18n: y18n({
^
TypeError: y18n is not a function
at Object.<anonymous> (dist/test.js:5012:11)
at Object../node_modules/yargs/build/index.cjs (dist/test.js:5045:30)
at __webpack_require__ (dist/test.js:20:30)
at Object../node_modules/yargs/index.cjs (dist/test.js:5061:32)
at __webpack_require__ (dist/test.js:20:30)
at Object../index.js (dist/test.js:96:13)
at __webpack_require__ (dist/test.js:20:30)
at dist/test.js:84:18
at Object.<anonymous> (dist/test.js:87:10)
at Module._compile (internal/modules/cjs/loader.js:1137:30)
Note: I was able to get it to work via some strange settings
var path = require('path');
module.exports = async (env, argv) => {
let config = {
mode: "development",
entry: {
"test": "./index.js",
},
output: {
path: path.resolve(__dirname, "dist")
},
target: 'node',
devtool: "source-map-inline",
externals: {
'y18n': 'commonjs2 y18n',
'yargs-parser': 'commonjs2 yargs-parser',
},
};
return config;
}
I had to explicitly tell webpack to import y18n and yargs-parser via commonjs2 methods.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:18 (11 by maintainers)
Top Results From Across the Web
Webpack suddenly broke - Stack Overflow
If you ran npm install in the last 8 hours you could have got the new release with breaking changes how loaders are...
Read more >How I solved and debugged my Webpack issue through trial ...
When webpack bundles your source code, it can become difficult to track down errors and warnings to their original location.
Read more >After upgrading to v5.12.1 from v5.11, webpack build breaks
Howdy! I started getting an error in my CI/CD pipeline last night after upgrading my project to v5.12.1. I can reliably reproduce it...
Read more >“It works on my machine”. When Webpack is broken ... - Medium
The initial step of creating a Webpack build process took a while. One of the reasons is that RPM package builders must run...
Read more >Production | webpack
... the best practices and utilities for building a production site or application. ... src/index.js', + }, + plugins: [ + new HtmlWebpackPlugin({...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.
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.