question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issue when bundling with webpack

See original GitHub issue

Good 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:closed
  • Created 6 years ago
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
Apidcloudcommented, Sep 20, 2017

Adding ‘.json’ to the configuration in webpack also solves the issue.

resolve: {
    // Look for modules in .js files first
    extensions: [".js", ".json"],

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.

1reaction
broofacommented, Sep 26, 2017

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 includes json 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 beyond mime. So fixing the problem here (and breaking with the “no-extension” convention) isn’t something I’m particularly interested in doing.


kieffer@MacBook-Pro-3$ npm install
added 4 packages in 2.609s

kieffer@MacBook-Pro-3$ ls node_modules/
babel-runtime mime

kieffer@MacBook-Pro-3$ npm run build

> webpack-babel@1.0.0 build /Users/kieffer/repos/webpack-babel
> webpack -d --config config/webpack.config.js

sh: webpack: command not found
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! webpack-babel@1.0.0 build: `webpack -d --config config/webpack.config.js`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the webpack-babel@1.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/kieffer/.npm/_logs/2017-09-26T16_41_08_608Z-debug.log

kieffer@MacBook-Pro-3$ npm install --only=dev

> fsevents@1.1.2 install /Users/kieffer/repos/webpack-babel/node_modules/fsevents
> node install

[fsevents] Success: "/Users/kieffer/repos/webpack-babel/node_modules/fsevents/lib/binding/Release/node-v51-darwin-x64/fse.node" is installed via remote

> uglifyjs-webpack-plugin@0.4.6 postinstall /Users/kieffer/repos/webpack-babel/node_modules/uglifyjs-webpack-plugin
> node lib/post_install.js

added 668 packages in 9.939s

kieffer@MacBook-Pro-3$ npm run build

> webpack-babel@1.0.0 build /Users/kieffer/repos/webpack-babel
> webpack -d --config config/webpack.config.js

Hash: d3f76fa6a16af1f4350d
Version: webpack 3.5.2
Time: 1241ms
                       Asset    Size  Chunks                    Chunk Names
webpack-babel.browser.min.js  337 kB       0  [emitted]  [big]  main
  [51] multi index.js 28 bytes {0} [built]
  [52] ./src/index.js + 3 modules 3.51 kB {0} [built]
    + 100 hidden modules

ERROR in ./node_modules/mime/index.js
Module not found: Error: Can't resolve './types/standard' in '/Users/kieffer/repos/webpack-babel/node_modules/mime'
 @ ./node_modules/mime/index.js 4:26-53
 @ ./src/core/snake.js
 @ ./src/core/index.js
 @ ./src/index.js
 @ multi index.js

ERROR in ./node_modules/mime/index.js
Module not found: Error: Can't resolve './types/other' in '/Users/kieffer/repos/webpack-babel/node_modules/mime'
 @ ./node_modules/mime/index.js 4:55-79
 @ ./src/core/snake.js
 @ ./src/core/index.js
 @ ./src/index.js
 @ multi index.js
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! webpack-babel@1.0.0 build: `webpack -d --config config/webpack.config.js`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the webpack-babel@1.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/kieffer/.npm/_logs/2017-09-26T16_38_18_589Z-debug.log
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found