Issue when bundling with webpack
See original GitHub issueGood evening!
While attempting to use your package with webpack, I’ve noticed an issue in index.js:
ERROR in ./node_modules/mime/index.js
Module not found: Error: Can't resolve './types/other' in 'test-project\node_modules\mime'
@ ./node_modules/mime/index.js 4:55-79
ERROR in ./node_modules/mime/index.js
Module not found: Error: Can't resolve './types/standard' in 'test-project\node_modules\mime'
@ ./node_modules/mime/index.js 4:26-53
Doing specific requires does the trick (note the extension):
module.exports = new Mime(
require('./types/standard.json'),
require('./types/other.json')
);
Let me know if you want me to do a PR.
Thanks!
Issue Analytics
- State:
- Created 6 years ago
- Comments:12 (7 by maintainers)
Top Results From Across the Web
Issue when bundling with webpack · Issue #172 · broofa/mime
While attempting to use your package with webpack, I've noticed an issue in index.js: ERROR in ./node_modules/mime/index.js Module not found: Error: Can't ...
Read more >Introduction to Module Bundling with Webpack - Medium
To perform module bundling, Webpack conducts a process called dependency resolution, where Webpack looks through all the dependencies for ...
Read more >Code Splitting - webpack
This feature allows you to split your code into various bundles which can then be loaded on demand or in parallel. It can...
Read more >Javascript bundled with webpack not working - Stack Overflow
Javascript bundled with webpack not working · 1 · Run the command npm run build and make sure all the files are generated...
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 >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 FreeTop 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
Top GitHub Comments
Adding ‘.json’ to the configuration in webpack also solves the issue.
Still, it’s a workaround and I would say it could be avoided if mime package used the extension in the require statements in the first place. It doesn’t feel right to adjust a bundler configuration based on a 3rd party package’s dependencies (i.e., it’s not even something to do with mime directly, but a dependency within. I don’t use json files in my project, so adding that to webpack purely because of that doesn’t feel right at all).
I guess a repository with a standard webpack configuration without the extension ‘.json’ should reproduce the errors mentioned above.
Checked out
issueNodeMime
branch. Had some weirdness with npm not installing devDependencies (see below). Eventually got it repro’ing your error though.Looks like the problem is that you’re supplying a custom definition of
config.resolve.extensions
. The default value of that field includesjson
as an extension, but in your definition, you only specify js and jsx.Webpack is almost certainly “working as designed” here. Regardless of whether this is a good thing, this is well-documented behavior for CommonJS module loading. Omitting
json
as an extension almost certainly breaks many other modules beyondmime
. So fixing the problem here (and breaking with the “no-extension” convention) isn’t something I’m particularly interested in doing.