broofa / mime

Mime types for JavaScript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Use mime.getExtension() without `path` using Webpack 5 (via CRA v5)

sww314 opened this issue · comments

Working with an app migrating to CRA 5.
Previously we used mime-types but they point to this package:
jshttp/mime-types#82 (comment)

However, we get the same error. Only looking for one feature which is converting a mime-type to a file extension.

I can work on the polyfill, but if this is a browser package then should I need it?

Module not found: Error: Can't resolve 'path' in '/Users/scottwhite/workspace/huvr/frontend/node_modules/mime'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
	- add a fallback 'resolve.fallback: { "path": require.resolve("path-browserify") }'
	- install 'path-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
	resolve.fallback: { "path": false }

What version of mime are you using? This project doesn't depend on the path lib, and hasn't since v1.x (circa 2017). It should work just fine in the browser.

This project doesn't depend on the path lib

Sorry, I'm realizing there's a small caveat to this. The CLI script in the beta release does use the path lib. But that's not part of the dependency chain for import 'mime'. It shouldn't be something Webpack is concerned with.

It works now - something strange happened with npm when I removed mime-types and added mime. A glitch in the npm matrix... thanks for the fast response and the package.

Glad you got it figured. BTW, be aware I just published mime@4.0.0, in case you're blindly taking major-version updates anywhere.