web-infra-dev / garfish

A powerful micro front-end framework 🚚

Home Page:https://www.garfishjs.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SyntaxError: Identifier 'exports' has already been declared

hakushinring opened this issue · comments

Describe the bug

vite cli 新建react主应用,微应用。按照官网配置后报错
image

Reproduction

https://github.com/hakushinring/garfish-test

Used Package Manager

npm

System Info

git clone https://github.com/hakushinring/garfish-test.git
cd main-app
npm install && npm run dev

cd vite-project
npm install && npm run dev


### Validations

- [X] Read the [docs](https://garfishjs.org/quick-start).
- [X] Read the [common issues list](https://garfishjs.org/issues).
- [X] Check that there isn't [already an issue](https://github.com/modern-js-dev/garfish/issues) that reports the same bug to avoid creating a duplicate.
- [X] Make sure this is a Garfish issue and not a framework-specific issue.
- [X] The provided reproduction is a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) of the bug.

看起来是 vite 构建导致产物出现了异常,跟 Garfish 看起来没有关系,浏览器请求的源码:

image

浏览器实际返回的源码
image

现在版本的vite不能通过直接删除热更新插件来关闭热更新了,hmr:false的设置没效果,garfish这边能不能提供一些方案绕过这个限制,现在vite流行程度还是挺高的

主要是 vite 在 react 热更新下的源码转换存在问题,这个 Garfish 这边没有办法调整

commented

我想到了个办法解决,在子应用html里最前面加个no-entry的声明就好:

<script type="garfish-no-entry">
{
   "https://xxx/@react-refresh.js": true
}
</script>
commented

@vitejs/plugin-react插件可通过fastRefresh配置是否启用react-refresh。禁用react-refresh可避免发生这种错误。

import { defineConfig, loadEnv } from 'vite'
import react from '@vitejs/plugin-react'

// https://vitejs.dev/config/
export default defineConfig(({ mode }) => ({
  // ...
  plugins: [
    react({
      fastRefresh: false
    }),
  ],
}))
commented

此问题已有解决方案,升级到最新版,参考issue文档配置即可