Skip to content

TypeError: Cannot read properties of undefined (reading '__GARFISH_EXPORTS__') #666

Open
@festina-lente-z

Description

@festina-lente-z

复现 demo

https://github.com/festina-lente-z/react-vite-garfish-demo/tree/feat/garfish-exports-undefined

问题

react子应用关闭沙箱,vite启动时,引入 rxjs 报错,但是打开沙箱引入 GarfishEsModule() 插件正常显示。报错如下图所示:

image

我自己这边进行排查之后,发现 rxjs 和 garfish 的 window 冲突了。

我在源码中加入了 console.log(window),代码如下

const blobUrl = this.createBlobUrl(`import.meta.url='${url}';console.log(window);${this.app.isNoEntryScript(url) ? noEntryEnvVarStr : envVarStr}${scriptCode}
${sourcemap}`);

当运行到 rxjs 内部时,打印的 window 与其他依赖不一致:

image

请问有比较好的解决方案吗?

Reproduction

https://github.com/festina-lente-z/react-vite-garfish-demo/tree/feat/garfish-exports-undefined

Used Package Manager

pnpm

System Info

System:
    OS: macOS 14.2.1
    CPU: (8) arm64 Apple M2
    Memory: 67.70 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.19.1 - ~/.nvm/versions/node/v18.19.1/bin/node
    Yarn: 1.22.21 - /opt/homebrew/bin/yarn
    npm: 10.2.4 - ~/.nvm/versions/node/v18.19.1/bin/npm
    pnpm: 8.15.3 - /opt/homebrew/bin/pnpm
  Browsers:
    Chrome: 123.0.6312.87
    Safari: 17.2.1
  npmPackages:
    @garfish/bridge-react-v18: ^1.17.5 => 1.17.5
    @garfish/es-module: ^1.17.5 => 1.17.5
    garfish: ^1.17.5 => 1.17.5

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions