Skip to content

Commit

Permalink
Merge pull request #11601 from Hornwitser/improve-suggested-polyfill-…
Browse files Browse the repository at this point in the history
…config

Improve suggested Node.js polyfill config
  • Loading branch information
sokra authored Oct 8, 2020
2 parents 9b5cce9 + 1acb996 commit 5573fed
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
28 changes: 12 additions & 16 deletions lib/ModuleNotFoundError.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
};
Expand All @@ -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- install '${dependency}'\n`;
} else {
message += `If you want to include a polyfill, you need to install '${dependency}'.\n`;
}
message +=
"If you want to include a polyfill, you need to:\n" +
`\t- add a fallback 'resolve.fallback: { "${request}": require.resolve("${alias}") }'\n` +
`\t- 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 }`;
Expand Down
6 changes: 4 additions & 2 deletions test/__snapshots__/StatsTestCases.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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 }
Expand Down

0 comments on commit 5573fed

Please sign in to comment.