Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: After building and running preview locally, error message: Cannot read properties of undefined (reading 'call') #2934

Closed
JayMo666 opened this issue Jul 16, 2024 · 17 comments
Assignees
Labels
🐞 bug Something isn't working need reproduction

Comments

@JayMo666
Copy link

JayMo666 commented Jul 16, 2024

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

报错如下:
image

把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
@JayMo666 JayMo666 added the 🐞 bug Something isn't working label Jul 16, 2024
@SoonIter
Copy link
Member

This problem seems to be related to rspack. The treeshaking optimization of build has led to the loss of some modules.
Can you provide a minimum reproduction repo?

Copy link
Contributor

Hello @JayMo666. Please provide a reproduction repository or online demo. For background, see Why reproductions are required. Thanks ❤️

@chenjiahan chenjiahan changed the title [Bug]: build后在本地运行preview后,报错:Cannot read properties of undefined (reading 'call') [Bug]: After building and running preview locally, error message: Cannot read properties of undefined (reading 'call') Jul 16, 2024
@belizariogr
Copy link

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

@SoonIter
Copy link
Member

SoonIter commented Jul 17, 2024

investigation

This error message may correspond to multiple errors. As for https://github.com/belizariogr/rsbuild-error, it is related to Rspack.

./node_modules/react-query/es/react/types.js is an empty file => __webpack_require__(null)

image

the behavior in webpack is correct.

image

@f312213213
Copy link

Same error here!
rsbuild version: "@rsbuild/core": "0.5.9" -> "1.0.0-alpha.2"

rsbuild dev works normally, but use rsbuild preview to start the production build server will throw the error:
TypeError: Cannot read properties of undefined (reading 'call')

CleanShot 2024-07-19 at 11 31 49@2x

@SoonIter
Copy link
Member

Same error here! rsbuild version: "@rsbuild/core": "0.5.9" -> "1.0.0-alpha.2"

The error message may be the same, but the reasons for the error may be different. Could you provide a minimum reproduction? :D

@kamalbennani
Copy link

I've got the same error, this is the non-transpiled code.

Screenshot 2024-07-20 at 13 16 35

In another working build, the transpiled code looks like this.

Screenshot 2024-07-20 at 13 17 40

@kamalbennani
Copy link

I've just realized that the difference between the two builds is that the working one, I used to have only one Source Entry and for the non-working one I have 3 entries, which imports the same "lib" in this case "react-i18next"

@xc2
Copy link
Collaborator

xc2 commented Jul 20, 2024

@belizariogr @JayMo666 this issue has been solved in web-infra-dev/rspack#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/core to nightly.

Setting tools.rspack.optimization.usedExports to false would be an alternative workaround if you don't want or don't know to overrides the package.

@xc2 xc2 closed this as completed Jul 20, 2024
@xc2
Copy link
Collaborator

xc2 commented Jul 20, 2024

@kamalbennani There could be another underlying cause for your issue. If the nightly version of @rspack/core doesn't help you out, please feel free to open a new issue with repro.

@kamalbennani
Copy link

Setting tools.rspack.optimization.usedExports to false worked for me. I will wait for a new release to see if the fix you pushed resolves my issue. If it doesn't, I will open an issue with a reproducible repository.

@f312213213
Copy link

Setting tools.rspack.optimization.usedExports to false also worked for me, thanks!

@ckken
Copy link

ckken commented Oct 22, 2024

+1

@ckken
Copy link

ckken commented Oct 22, 2024

Problems remain!

@chenjiahan
Copy link
Member

Please create a new issue and provide an reproduction

@ckken
Copy link

ckken commented Oct 22, 2024

There is no problem if you cancel the compression, and the problem only occurs before Chrome 109. I suspect it is still a compression problem.

@ckken
Copy link

ckken commented Oct 22, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working need reproduction
Projects
None yet
Development

No branches or pull requests

9 participants