SyntaxError: Identifier 'exports' has already been declared
hakushinring opened this issue · comments
Describe the bug
vite cli 新建react主应用,微应用。按照官网配置后报错
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不能通过直接删除热更新插件来关闭热更新了,hmr:false
的设置没效果,garfish这边能不能提供一些方案绕过这个限制,现在vite流行程度还是挺高的
主要是 vite 在 react 热更新下的源码转换存在问题,这个 Garfish 这边没有办法调整
我想到了个办法解决,在子应用html里最前面加个no-entry
的声明就好:
<script type="garfish-no-entry">
{
"https://xxx/@react-refresh.js": true
}
</script>
@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
}),
],
}))