| | |
| | | const WebpackError = require("./WebpackError"); |
| | | const makeSerializable = require("./util/makeSerializable"); |
| | | |
| | | /** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */ |
| | | /** @typedef {import("./Dependency").SourcePosition} SourcePosition */ |
| | | /** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */ |
| | | /** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */ |
| | |
| | | |
| | | class ModuleParseError extends WebpackError { |
| | | /** |
| | | * Creates an instance of ModuleParseError. |
| | | * @param {string | Buffer} source source code |
| | | * @param {Error & { loc?: SourcePosition }} err the parse error |
| | | * @param {string[]} loaders the loaders used |
| | |
| | | */ |
| | | constructor(source, err, loaders, type) { |
| | | let message = `Module parse failed: ${err && err.message}`; |
| | | /** @type {undefined | DependencyLocation} */ |
| | | let loc; |
| | | |
| | | if ( |
| | | ((Buffer.isBuffer(source) && source.slice(0, 4).equals(WASM_HEADER)) || |
| | | ((Buffer.isBuffer(source) && source.subarray(0, 4).equals(WASM_HEADER)) || |
| | | (typeof source === "string" && /^\0asm/.test(source))) && |
| | | !type.startsWith("webassembly") |
| | | ) { |
| | |
| | | "\nFor files that transpile to WebAssembly, make sure to set the module type in the 'module.rules' section of the config (e. g. 'type: \"webassembly/async\"')."; |
| | | } else if (!loaders) { |
| | | message += |
| | | "\nYou may need an appropriate loader to handle this file type."; |
| | | "\nYou may need an appropriate loader to handle this file type. " + |
| | | "See https://webpack.js.org/concepts/loaders"; |
| | | } else if (loaders.length >= 1) { |
| | | message += `\nFile was processed with these loaders:${loaders |
| | | .map((loader) => `\n * ${loader}`) |
| | |
| | | |
| | | super(message); |
| | | |
| | | /** @type {string} */ |
| | | this.name = "ModuleParseError"; |
| | | this.loc = loc; |
| | | this.error = err; |
| | | } |
| | | |
| | | /** |
| | | * Serializes this instance into the provided serializer context. |
| | | * @param {ObjectSerializerContext} context context |
| | | */ |
| | | serialize(context) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Restores this instance from the provided deserializer context. |
| | | * @param {ObjectDeserializerContext} context context |
| | | */ |
| | | deserialize(context) { |