| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2018-07-30 23:08:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-19 04:38:55 +08:00
										 |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-25 05:17:47 +08:00
										 |  |  | const WebpackError = require("./WebpackError"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-03 02:09:36 +08:00
										 |  |  | /** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */ | 
					
						
							| 
									
										
										
										
											2018-11-07 21:03:25 +08:00
										 |  |  | /** @typedef {import("./Module")} Module */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-06 18:36:32 +08:00
										 |  |  | const previouslyPolyfilledBuiltinModules = { | 
					
						
							| 
									
										
										
										
											2020-10-08 04:00:48 +08:00
										 |  |  | 	assert: "assert/", | 
					
						
							|  |  |  | 	buffer: "buffer/", | 
					
						
							| 
									
										
										
										
											2018-12-06 18:36:32 +08:00
										 |  |  | 	console: "console-browserify", | 
					
						
							|  |  |  | 	constants: "constants-browserify", | 
					
						
							|  |  |  | 	crypto: "crypto-browserify", | 
					
						
							|  |  |  | 	domain: "domain-browser", | 
					
						
							| 
									
										
										
										
											2020-10-08 04:00:48 +08:00
										 |  |  | 	events: "events/", | 
					
						
							| 
									
										
										
										
											2018-12-06 18:36:32 +08:00
										 |  |  | 	http: "stream-http", | 
					
						
							|  |  |  | 	https: "https-browserify", | 
					
						
							|  |  |  | 	os: "os-browserify/browser", | 
					
						
							|  |  |  | 	path: "path-browserify", | 
					
						
							| 
									
										
										
										
											2020-10-08 04:00:48 +08:00
										 |  |  | 	punycode: "punycode/", | 
					
						
							| 
									
										
										
										
											2018-12-06 18:36:32 +08:00
										 |  |  | 	process: "process/browser", | 
					
						
							|  |  |  | 	querystring: "querystring-es3", | 
					
						
							|  |  |  | 	stream: "stream-browserify", | 
					
						
							|  |  |  | 	_stream_duplex: "readable-stream/duplex", | 
					
						
							|  |  |  | 	_stream_passthrough: "readable-stream/passthrough", | 
					
						
							|  |  |  | 	_stream_readable: "readable-stream/readable", | 
					
						
							|  |  |  | 	_stream_transform: "readable-stream/transform", | 
					
						
							|  |  |  | 	_stream_writable: "readable-stream/writable", | 
					
						
							| 
									
										
										
										
											2020-10-08 04:00:48 +08:00
										 |  |  | 	string_decoder: "string_decoder/", | 
					
						
							|  |  |  | 	sys: "util/", | 
					
						
							| 
									
										
										
										
											2018-12-06 18:36:32 +08:00
										 |  |  | 	timers: "timers-browserify", | 
					
						
							|  |  |  | 	tty: "tty-browserify", | 
					
						
							| 
									
										
										
										
											2020-10-08 04:00:48 +08:00
										 |  |  | 	url: "url/", | 
					
						
							|  |  |  | 	util: "util/", | 
					
						
							| 
									
										
										
										
											2018-12-06 18:36:32 +08:00
										 |  |  | 	vm: "vm-browserify", | 
					
						
							|  |  |  | 	zlib: "browserify-zlib" | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-25 05:17:47 +08:00
										 |  |  | class ModuleNotFoundError extends WebpackError { | 
					
						
							| 
									
										
										
										
											2018-11-07 21:03:25 +08:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2023-06-13 01:24:59 +08:00
										 |  |  | 	 * @param {Module | null} module module tied to dependency | 
					
						
							| 
									
										
										
										
											2025-03-27 08:07:25 +08:00
										 |  |  | 	 * @param {Error & { details?: string }} err error thrown | 
					
						
							| 
									
										
										
										
											2020-08-03 02:09:36 +08:00
										 |  |  | 	 * @param {DependencyLocation} loc location of dependency | 
					
						
							| 
									
										
										
										
											2018-11-07 21:03:25 +08:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-09-07 20:11:48 +08:00
										 |  |  | 	constructor(module, err, loc) { | 
					
						
							| 
									
										
										
										
											2018-12-06 18:36:32 +08:00
										 |  |  | 		let message = `Module not found: ${err.toString()}`; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// TODO remove in webpack 6
 | 
					
						
							|  |  |  | 		const match = err.message.match(/Can't resolve '([^']+)'/); | 
					
						
							|  |  |  | 		if (match) { | 
					
						
							|  |  |  | 			const request = match[1]; | 
					
						
							| 
									
										
										
										
											2023-06-13 01:24:59 +08:00
										 |  |  | 			const alias = | 
					
						
							|  |  |  | 				previouslyPolyfilledBuiltinModules[ | 
					
						
							|  |  |  | 					/** @type {keyof previouslyPolyfilledBuiltinModules} */ (request) | 
					
						
							|  |  |  | 				]; | 
					
						
							| 
									
										
										
										
											2018-12-06 18:36:32 +08:00
										 |  |  | 			if (alias) { | 
					
						
							|  |  |  | 				const pathIndex = alias.indexOf("/"); | 
					
						
							|  |  |  | 				const dependency = pathIndex > 0 ? alias.slice(0, pathIndex) : alias; | 
					
						
							|  |  |  | 				message += | 
					
						
							|  |  |  | 					"\n\n" + | 
					
						
							|  |  |  | 					"BREAKING CHANGE: " + | 
					
						
							|  |  |  | 					"webpack < 5 used to include polyfills for node.js core modules by default.\n" + | 
					
						
							| 
									
										
										
										
											2020-07-13 02:07:56 +08:00
										 |  |  | 					"This is no longer the case. Verify if you need this module and configure a polyfill for it.\n\n"; | 
					
						
							| 
									
										
										
										
											2020-10-08 04:00:48 +08:00
										 |  |  | 				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`; | 
					
						
							| 
									
										
										
										
											2018-12-06 18:36:32 +08:00
										 |  |  | 				message += | 
					
						
							|  |  |  | 					"If you don't want to include a polyfill, you can use an empty module like this:\n" + | 
					
						
							| 
									
										
										
										
											2020-09-16 12:58:59 +08:00
										 |  |  | 					`\tresolve.fallback: { "${request}": false }`; | 
					
						
							| 
									
										
										
										
											2018-12-06 18:36:32 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		super(message); | 
					
						
							| 
									
										
										
										
											2017-02-16 03:55:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-19 04:38:55 +08:00
										 |  |  | 		this.name = "ModuleNotFoundError"; | 
					
						
							|  |  |  | 		this.details = err.details; | 
					
						
							|  |  |  | 		this.module = module; | 
					
						
							|  |  |  | 		this.error = err; | 
					
						
							| 
									
										
										
										
											2018-09-07 20:11:48 +08:00
										 |  |  | 		this.loc = loc; | 
					
						
							| 
									
										
										
										
											2017-01-19 04:38:55 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-19 04:38:55 +08:00
										 |  |  | module.exports = ModuleNotFoundError; |