rsbuild: [Bug]: After building and running preview locally, error message: Cannot read properties of undefined (reading 'call')
Version
System:
OS: macOS 14.5
CPU: (8) arm64 Apple M1 Pro
Memory: 85.45 MB / 16.00 GB
Shell: 5.9 - /bin/zsh
Browsers:
Chrome: 126.0.6478.127
Chrome Canary: 128.0.6598.0
Safari: 17.5
npmPackages:
@rsbuild/core: 1.0.1-beta.1 => 1.0.1-beta.1
@rsbuild/plugin-basic-ssl: ^1.0.0 => 1.0.0
@rsbuild/plugin-less: 1.0.1-beta.1 => 1.0.1-beta.1
@rsbuild/plugin-react: 1.0.1-beta.1 => 1.0.1-beta.1
@rsbuild/plugin-styled-components: 1.0.1-beta.1 => 1.0.1-beta.1
@rsbuild/plugin-svgr: 1.0.1-beta.1 => 1.0.1-beta.1
Details
报错如下:
把e[a].call(r.exports, r, r.exports, n)改为 return e[a]?.call(r.exports, r, r.exports, n) 就可以解决,增加可选符号。
本地运行 pnpm run dev 是没问题的,可以访问。 rsbuild.config.ts文件:
import { pluginReact } from '@rsbuild/plugin-react';
import { defineConfig } from '@rsbuild/core';
import { pluginSvgr } from '@rsbuild/plugin-svgr';
import { pluginLess } from '@rsbuild/plugin-less';
import { RsdoctorRspackPlugin } from '@rsdoctor/rspack-plugin';
import { pluginBasicSsl } from '@rsbuild/plugin-basic-ssl';
import { pluginStyledComponents } from '@rsbuild/plugin-styled-components';
export default defineConfig({
plugins: [
pluginStyledComponents(),
pluginBasicSsl(),
pluginLess(),
pluginSvgr({
mixedImport: true,
svgrOptions: {
exportType: 'named',
},
}),
pluginReact(),
],
tools: {
// @ts-ignore
rspack(_, { appendPlugins }) {
// 仅在 RSDOCTOR 为 true 时注册插件,因为插件会增加构建耗时
if (process.env.RSDOCTOR) {
appendPlugins(
new RsdoctorRspackPlugin({
// 插件选项
supports: {
generateTileGraph: true,
},
}),
);
}
},
},
source: {
entry: {
index: './src/main.tsx',
},
},
output: {
sourceMap: {
js: 'source-map',
},
},
server: {
proxy: [
{
ws: true,
// changeOrigin: true,
context: ['xxx'],
target: 'yyy.com,
},
],
},
});
Reproduce link
无
Reproduce Steps
1、
pnpm run build //rsbuild build
2、
pnpm run preview // rsbuild preview
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 17 (5 by maintainers)
@belizariogr @JayMo666 this issue has been solved in https://github.com/web-infra-dev/rspack/issues/7170 and the fix will be included in the next release.
If you’d like to try out it at this moment, please overrides
@rspack/coretonightly.Setting
tools.rspack.optimization.usedExportstofalsewould be an alternative workaround if you don’t want or don’t know to overrides the package.Here is a repo with the same error… You can run with “npm start” and it will run normally… but, if you run “npm run build”… it will throw this same error.
https://github.com/belizariogr/rsbuild-error