By default, Rsbuild does not compile JavaScript files under node_modules
. If an npm package used in the project contains ESNext syntax, it will be bundled into the output.
When this happens, you can specify directories or modules that need to be compiled additionally through the source.include configuration option.
Error: [object Object] is not a PostCSS plugin
?Currently, Rsbuild is using PostCSS v8. If you encounter the Error: [object Object] is not a PostCSS plugin
error during the compilation process, it is usually caused by referencing the wrong version of PostCSS, for example, the version of postcss
(peerDependencies) in cssnano
does not meet expectations.
You can find the dependencies of UNMET PEER DEPENDENCY
through npm ls postcss
, and then install the correct version of dependencies by specifying the PostCSS version in package.json.
You may need additional loader
?If the following error message is encountered during the compilation process, it means that there are individual files that cannot be compiled correctly.
Please check if any file formats not supported by Rsbuild are being referenced, and configure the corresponding Rspack loader to compile them.
export 'foo' (imported as 'foo') was not found in './utils'
?If you encounter this error during the compilation process, it means that your code is referencing an export that does not exist.
For example, in the following code, index.ts
is importing the foo
variable from utils.ts
, but utils.ts
only exports the bar
variable.
In this case, Rsbuild will throw the following error:
If you encounter this issue, the first step is to check the import/export statements in your code and correct any invalid code.
There are some common mistakes:
type
modifier, causing compilers like Babel to fail in recognizing the type export, resulting in compilation errors.In some cases, the error may be caused by a third-party dependency that you cannot modify directly. In this situation, if you are sure that the issue does not affect your application, you can add the following configuration to change the log level from error
to warn
:
However, it is important to contact the developer of the third-party dependency immediately to fix the issue.
You can refer to the webpack documentation for more details on module.parser.javascript.exportsPresence.
Rsbuild will enable the tree shaking function of Rspack by default during production construction. Whether tree shaking can take effect depends on whether the business code can meet the tree shaking conditions of Rspack.
If you encounter the problem that tree shaking does not take effect, you can check whether the sideEffects
configuration of the relevant npm package is correct. If you don't know what sideEffects
is, or are interested in the principles behind tree shaking, you can read the following two documents:
JavaScript heap out of memory
when compiling?This error indicates that there is a memory overflow problem during the packaging process. In most cases, it is because the bundled content exceeds the default memory limit of Node.js.
In case of OOM issues, the easiest way to fix this is by increasing the memory cap, Node.js provides the --max-old-space-size
option to set this. You can set this parameter by adding NODE_OPTIONS before the CLI command.
For example, add parameters before the rsbuild build
command:
If you are executing other commands, such as rsbuild dev
, please add parameters before the corresponding command.
The value of the max_old_space_size
parameter represents the upper limit of the memory size (MB). Generally, it can be set to 16384
(16GB).
The following parameters are explained in more detail in the official Node.js documentation:
In addition to increasing the memory limit, it is also a solution to improve efficiency by enabling some compilation strategies, please refer to Improve Build Performance.
If the above methods cannot solve your problem, it may be that some abnormal logic in the project has caused memory overflow. You can debug recent code changes and locate the root cause of problems. If it cannot be located, please contact us.
Can't resolve 'core-js/modules/xxx.js'
when compiling?If you get an error similar to the following when compiling, it means that core-js cannot be resolved properly in the project.
Usually, you don't need to install core-js
in the project, because the Rsbuild already has a built-in core-js
v3.
If there is an error that core-js
cannot be found, there may be several reasons:
alias
configuration of Rsbuild, causing the incorrect resolution of the core-js
path when referenced. In this case, you can check the alias
configuration of the project.core-js
v2. In this case, you usually need to find out the corresponding code and upgrade core-js
to the v3.node_modules
imported core-js
, but does not declare the core-js
dependency in dependencies
. In this case, you need to declare the core-js
dependency in the corresponding npm package, or install a copy of core-js
in the project root directory.If the @types/lodash
package is installed in your project, you may import some types from lodash
, such as the DebouncedFunc
type:
Rsbuild will throw an error after compiling the above code:
The reason is that Rsbuild has enabled the babel-plugin-lodash plugin by default to optimize the bundle size of lodash, but Babel cannot distinguish between "value" and "type", which resulting in an exception in the compiled code.
The solution is to use TypeScript's import type
syntax to explicitly declare the DebouncedFunc
type:
In any case, it is recommended to use import type
to import types, this will help the compiler to identify the type.
Compared with the v3 version, the Less v4 version has some differences in the way of writing division:
The built-in Less version of Rsbuild is v4, and the writing method of the lower version will not take effect. Please pay attention to the distinction.
The writing of division in Less can also be modified through configuration options, see Less - Math.
TypeError: Cannot delete property 'xxx' of #<Object>
This error indicates that a read-only configuration option was deleted during the compilation process. Normally, we do not want any operation to directly modify the incoming configuration when compiling, but it is difficult to restrict the behavior of underlying plugins (such as postcss-loader, etc). If this error occurs, please contact the Rsbuild developer and we will need to do something special with that configuration.
The same type of error is also reported:
TypeError: Cannot add property xxx, object is not extensible
TypeError: Cannot assign to read only property 'xxx' of object '#<Object>