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] MPA getConfigFromEntryFile 选项开启后不能与浏览器环境变量兼容 #12103

Open
liaobin312716 opened this issue Jan 29, 2024 · 2 comments

Comments

@liaobin312716
Copy link

配置 MPA 后启动报错

在开启 MPA 的应用中使用到 window 变量会报错
image

复现路径

基于 Umi 官方的 MPA 示例,只加了一行代码,即可复现。
const isPre = /pre-|local/.test(window.location.host);
mpaTest.zip

  1. 下载测试代码
  2. npm i 安装依赖
  3. npm start 启动
    就会出现 ReferenceError: window is not defined 错误

上下文

  • Umi Version: ^4.0.79
  • Node Version: v14.18.0
  • Platform: macOS 12.0.1
@fz6m
Copy link
Member

fz6m commented Jan 30, 2024

这是因为这个 example 开了 mpa 的一个实验性选项 getConfigFromEntryFile ,这个选项允许你在 tsx 文件里导出这个页面的标题配置,但是在你反馈的这个 case 里确实出现了问题不能运行。

如果要用 mpa ,就把这个选项去掉吧,然后每页的配置写到 config.json 或者 umi 配置文件 mpa.entry 里(详见 mpa 文档 )。

你可能并不需要 mpa 功能,这个是给蚂蚁少量 h5 手机页面的项目使用的,没有路由,只是一个单纯的 /xxx.html 页面,对大多数人来说,这个功能是用不到的。

@fz6m fz6m changed the title [Bug] MPA 应用启动报错 ReferenceError: window is not defined [Bug] MPA getConfigFromEntryFile 选项开启后不能与浏览器环境变量兼容 Jan 30, 2024
@liaobin312716
Copy link
Author

感谢,我试试。 我们的场景有一部分属于类似于 ToB 的导购页面,每个页面都是独立的,没有路由,用 SPA 比较重。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants