vite-plugin-federation icon indicating copy to clipboard operation
vite-plugin-federation copied to clipboard

vite 2.9.9 报错

Open ckken opened this issue 2 years ago • 11 comments

Versions

  • originjs: 1.1.6
  • node: 12
  • vite:2.9.9

vite build

Top-level await is not available in the configured target environment ("chrome87", "edge88", "es2019", "firefox78", "safari13.1")
1  |  import {importShared} from './__federation_fn_import.js'
2  |  const {r:react} = await importShared('react')
   |                    ^
3  |
4  |  var jsxRuntime = {exports: {}};

vite dev

Failed to resolve import "host/App" from "src\App.tsx". Does the file exist?
上午11:54:24 [vite] Internal server error: Failed to resolve import "host/App" from "src\App.tsx". Does the file exist?
  Plugin: vite:import-analysis
  File: D:/Develop/vite-module-federation/projects/app/src/App.tsx

demo

ckken avatar May 12 '22 03:05 ckken

remote 在 dev环境下 不生成 remotejs 入口

ckken avatar May 12 '22 07:05 ckken

如果使用的是ESM格式的话,会使用top-level await特性,必须设置target:'esnext'

export default defineConfig({
  build: {
	target: 'esnext',
  }
})

ruleeeer avatar May 12 '22 07:05 ruleeeer

dev模式有一些限制条件,只有完全的host端(不能包含任何expose)才可以使用dev模式,这是因为vite在dev模式下不允许添加chunk,自然也无法生成remoteEntry

ruleeeer avatar May 12 '22 07:05 ruleeeer

如果使用的框架是react,我不建议使用dev模式,因为react的打包格式一直是cjs,调整dev(esbuild)和build(rollup)打包cjs库行为一致不是一件容易的事情,当然如果react升级为ESM的库,这个问题就不存在了

ruleeeer avatar May 12 '22 07:05 ruleeeer

目前比较大问题 卡在

[vite] Internal server error: Failed to resolve import "host/App" from "src\App.tsx". Does the file exist?
  Plugin: vite:import-analysis

ckken avatar May 12 '22 07:05 ckken

目前比较大问题 卡在

[vite] Internal server error: Failed to resolve import "host/App" from "src\App.tsx". Does the file exist?
  Plugin: vite:import-analysis

我用dev没有报错,而且react还是尽量用build吧,dev运行起来会有其他奇奇怪怪的打包问题

ruleeeer avatar May 12 '22 07:05 ruleeeer

https://github.com/ckken/vite-module-federation 根据约定更新了一轮

ckken avatar May 12 '22 07:05 ckken

会不会跟ts 有关

ckken avatar May 12 '22 07:05 ckken

你看看这个 https://github.com/originjs/vite-plugin-federation/issues/129#issuecomment-1048474627

ruleeeer avatar May 12 '22 07:05 ruleeeer

有加的

ckken avatar May 12 '22 10:05 ckken

Same error the plugin is just not working no matter what I am doing

paper-florent avatar Jun 20 '22 15:06 paper-florent

Since vite has now been upgraded to version 4.0, I'll close this issue.

flyfishzy avatar Jan 17 '23 11:01 flyfishzy