Skip to content

Browser environment (webpack) support #138

@slavafomin

Description

@slavafomin

Hello!

Right now, minimatch includes the following code:

var path = { sep: '/' }
try {
  path = require('path')
} catch (er) {
}

https://github.com/isaacs/minimatch/blob/master/minimatch.js#L4-L7

However, it doesn't work very well with the bundling tools like Webpack, because they need to resolve all the dependencies during the build time and not at runtime. Also, the browser environment doesn't has path module built-in.

This causes the following error in Webpack:

WARNING in …/node_modules/minimatch/minimatch.js 6:9-24
Module not found: Error: Can't resolve 'path' in '…/node_modules/minimatch'

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 }

Of course, we don't want to load polyfill just to satisfy the minimatch (which is using only the sep property from the path module) and we can't substitute it with the empty module also because it will break the minimatch logic.

I would suggest to introduce a more browser/bundler friendly approach.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions