output.module
- Type:
boolean
- Default:
false
- Version: Added in v1.5.0
Whether to output JavaScript files in ES modules format.
TIP
- This feature is currently experimental and only available when output.target is
'node'
.
- If you need to build JavaScript libraries in ESM format, we recommend using Rslib, which is an out-of-the-box library development tool built on top of Rsbuild.
Example
When building Node.js bundles, Rsbuild outputs CommonJS format by default. You can set output.module
to true
to output ES modules format:
rsbuild.config.ts
export default {
output: {
target: 'node',
module: true,
},
};
Running ESM bundles
To properly run ESM bundles in Node.js, you can choose either of the following approaches:
- Set the
type
field in package.json to 'module'
:
- Change the output JavaScript file extension to
.mjs
:
rsbuild.config.ts
export default {
output: {
filename: {
js: '[name].mjs',
},
},
};