mirror of https://github.com/webpack/webpack.git
Improve suggested Node.js polyfill config
Resolve fallback to an absolute path in the suggested config for the
Node.js polyfill. This is necessary in setups where where packages that
use the Node.js module are symlinked outside the package directory and
fail to resolve the fallback as a result.
A trailing slash is also necessary for packages that are shadowed by
builtin modules, i.e.: require.resolve("events") returns "events" while
require.resolve("events/") returns the path to the polyfill.
This commit is contained in:
parent
d10b08b4b5
commit
1acb9964ec
|
|
@ -11,18 +11,18 @@ const WebpackError = require("./WebpackError");
|
|||
/** @typedef {import("./Module")} Module */
|
||||
|
||||
const previouslyPolyfilledBuiltinModules = {
|
||||
assert: "assert",
|
||||
buffer: "buffer",
|
||||
assert: "assert/",
|
||||
buffer: "buffer/",
|
||||
console: "console-browserify",
|
||||
constants: "constants-browserify",
|
||||
crypto: "crypto-browserify",
|
||||
domain: "domain-browser",
|
||||
events: "events",
|
||||
events: "events/",
|
||||
http: "stream-http",
|
||||
https: "https-browserify",
|
||||
os: "os-browserify/browser",
|
||||
path: "path-browserify",
|
||||
punycode: "punycode",
|
||||
punycode: "punycode/",
|
||||
process: "process/browser",
|
||||
querystring: "querystring-es3",
|
||||
stream: "stream-browserify",
|
||||
|
|
@ -31,12 +31,12 @@ const previouslyPolyfilledBuiltinModules = {
|
|||
_stream_readable: "readable-stream/readable",
|
||||
_stream_transform: "readable-stream/transform",
|
||||
_stream_writable: "readable-stream/writable",
|
||||
string_decoder: "string_decoder",
|
||||
sys: "util",
|
||||
string_decoder: "string_decoder/",
|
||||
sys: "util/",
|
||||
timers: "timers-browserify",
|
||||
tty: "tty-browserify",
|
||||
url: "url",
|
||||
util: "util",
|
||||
url: "url/",
|
||||
util: "util/",
|
||||
vm: "vm-browserify",
|
||||
zlib: "browserify-zlib"
|
||||
};
|
||||
|
|
@ -63,14 +63,10 @@ class ModuleNotFoundError extends WebpackError {
|
|||
"BREAKING CHANGE: " +
|
||||
"webpack < 5 used to include polyfills for node.js core modules by default.\n" +
|
||||
"This is no longer the case. Verify if you need this module and configure a polyfill for it.\n\n";
|
||||
if (request !== alias) {
|
||||
message +=
|
||||
"If you want to include a polyfill, you need to:\n" +
|
||||
`\t- add an fallback 'resolve.fallback: { "${request}": "${alias}" }'\n` +
|
||||
`\t- add a fallback 'resolve.fallback: { "${request}": require.resolve("${alias}") }'\n` +
|
||||
`\t- install '${dependency}'\n`;
|
||||
} else {
|
||||
message += `If you want to include a polyfill, you need to install '${dependency}'.\n`;
|
||||
}
|
||||
message +=
|
||||
"If you don't want to include a polyfill, you can use an empty module like this:\n" +
|
||||
`\tresolve.fallback: { "${request}": false }`;
|
||||
|
|
|
|||
|
|
@ -1259,7 +1259,9 @@ Module not found: Error: Can't resolve 'buffer' in 'Xdir/module-not-found-error'
|
|||
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 install 'buffer'.
|
||||
If you want to include a polyfill, you need to:
|
||||
- add a fallback 'resolve.fallback: { \\"buffer\\": require.resolve(\\"buffer/\\") }'
|
||||
- install 'buffer'
|
||||
If you don't want to include a polyfill, you can use an empty module like this:
|
||||
resolve.fallback: { \\"buffer\\": false }
|
||||
|
||||
|
|
@ -1270,7 +1272,7 @@ BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules
|
|||
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 an fallback 'resolve.fallback: { \\"os\\": \\"os-browserify/browser\\" }'
|
||||
- add a fallback 'resolve.fallback: { \\"os\\": require.resolve(\\"os-browserify/browser\\") }'
|
||||
- install 'os-browserify'
|
||||
If you don't want to include a polyfill, you can use an empty module like this:
|
||||
resolve.fallback: { \\"os\\": false }
|
||||
|
|
|
|||
Loading…
Reference in New Issue