CC 4.0 License
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.
Node
The following Node.js options configure whether to polyfill or mock certain Node.js globals.
node.global
- Type:
boolean | 'warn' - Default:
'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.
Available values
true: Rspack injects a polyfill so thatglobalis available in the bundle. This ensures compatibility with code that relies on Node.js globals in non-Node runtimesfalse: No polyfill is provided. References toglobalremain untouched. If your target environment does not defineglobal, accessing it will throw aReferenceErrorat runtime'warn': Inject a polyfill liketrue, but also emit a warning whenglobalis used
Examples
For example, to disable global polyfill:
node.__filename
- Type:
boolean | 'mock' | 'warn-mock' | 'eval-only' - Default:
- If
targetdoes not includenode, defaults to'warn-mock'. - If
targetincludesnode, uses'node-module'if output.module is enabled, otherwise'eval-only'.
- If
Controls how Rspack handles the Node.js __filename and import.meta.filename variables when bundling for non-Node environments.
Available values
true: Replace with the source file path, relative to thecontextoptionfalse: Do nothing and keep the native behavior'mock': Replace with/index.js'mock': Replace with'/index.js''warn-mock': Replace with'/index.js', and emit a warning to indicate a potential Node.js dependency in the code'node-module': Only used when output.module is enabled. Replace__filenamein CommonJS with an equivalent implementation based onimport.meta.url, suitable for ESM output
Examples
For example, to leave __filename and import.meta.filename as it is:
To replace __filename in ESM output with fileURLToPath(import.meta.url):
node.__dirname
- Type:
boolean | 'mock' | 'warn-mock' | 'eval-only' - Default:
- If
targetdoes not includenode, defaults to'warn-mock'. - If
targetincludesnode, uses'node-module'if output.module is enabled, otherwise'eval-only'.
- If
Controls how Rspack handles the Node.js __dirname and import.meta.dirname variables when bundling for non-Node environments.
Available values
true: Replace with the directory path of the source file, relative to thecontextoptionfalse: Do nothing and keep the native behavior'mock': Replace with'/''eval-only': Equivalent tofalse'warn-mock': Replace with'/', and emit a warning to indicate a potential Node.js dependency in the code'node-module': Only used when output.module is enabled. Replace__dirnamein CommonJS with an equivalent implementation based onimport.meta.url, suitable for ESM output
Examples
For example, to leave __dirname and import.meta.dirname as it is:
To replace __dirname in ESM output with fileURLToPath(import.meta.url + "/.."):

