Hi I\'m a new to Webpack , currently I\'m adding this tool to my project, during bundling (webpack ...) jquery-dependent library I get an error like that:
Since jquery.placholder.min.js
is using UMD as its loading strategy, it's recognizing that it is required via a require
- and tries to require jQuery in the same way:
"object"==typeof module&&module.exports?require("jquery"):jQuery
Webpack sees require("jquery")
and tries to bundle the jQuery library (which does not exist in the node_modules).
The solution is to add jQuery as an external in your webpack.config.js
:
{
...
externals: {
// require("jquery") is external and available
// on the global var jQuery
"jquery": "jQuery"
}
}
When a module is marked as an external, Webpack knows not to bundle it, but instead use the global variable.