The content of this section is derived from the content of the following links and is subject to the CC BY 4.0 license.
The following contents can be assumed to be the result of modifications and deletions based on the original contents if not specifically stated.
The following Node.js options configure whether to polyfill or mock certain Node.js globals.
boolean | 'warn''warn'Controls whether Rspack should provide a polyfill for the Node.js global object when bundling for non-Node environments.
See the Node.js documentation for the exact behavior of this object.
Optional values:
true: Rspack injects a polyfill so that global is available in the bundle. This ensures compatibility with code that relies on Node.js globals in non-Node runtimes.false: No polyfill is provided. References to global remain untouched. If your target environment does not define global, accessing it will throw a ReferenceError at runtime.'warn': Inject a polyfill like true, but also emit a warning when global is used.For example, to disable global polyfill:
export default {
node: {
global: false,
},
};boolean | 'mock' | 'warn-mock' | 'eval-only''warn-mock', 'node-module' when output.module is enabledControls how Rspack handles the Node.js __filename variable when bundling for non-Node environments.
Optional values:
true: The filename of the input file relative to the context option.false: Rspack won't touch your __filename code, which means you have the regular Node.js __filename behavior. The filename of the output file when run in a Node.js environment.'mock': The fixed value '/index.js'.'warn-mock': Use the fixed value of '/index.js' but show a warning.'node-module': Replace __filename in CommonJS modules to fileURLToPath(import.meta.url) when output.module is enabled.'eval-only': Equivalent to false.For example, to leave __filename as it is:
export default {
node: {
__filename: false,
},
};boolean | 'mock' | 'warn-mock' | 'eval-only''warn-mock', 'node-module' when output.module is enabledControls how Rspack handles the Node.js __dirname variable when bundling for non-Node environments.
Optional values:
true: The dirname of the input file relative to the context option.false: Rspack won't touch your __dirname code, which means you have the regular Node.js __dirname behavior. The dirname of the output file when run in a Node.js environment.'mock': The fixed value '/'.'warn-mock': Use the fixed value of '/' but show a warning.'node-module': Replace __dirname in CommonJS modules to fileURLToPath(import.meta.url + "/..") when output.module is enabled.'eval-only': Equivalent to false.For example, to leave __dirname as it is:
export default {
node: {
__dirname: false,
},
};