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] EnvReplacer 在 Typescript Declare 环境下失效 #1673

Closed
Lemonnnnnnnnnnn opened this issue Oct 31, 2024 · 2 comments · Fixed by #1682
Closed

[Bug] EnvReplacer 在 Typescript Declare 环境下失效 #1673

Lemonnnnnnnnnnn opened this issue Oct 31, 2024 · 2 comments · Fixed by #1682
Assignees

Comments

@Lemonnnnnnnnnnn
Copy link

Lemonnnnnnnnnnn commented Oct 31, 2024

版本

  • umi: 4.3.6
  • mako: 0.9.3

问题

umi.define 与 typescript declare 合用时,报错:_ is not defined

最简复现

.umirc.ts :

import { defineConfig } from 'umi';

export default defineConfig({
    define: { 
        foo:1
    },
    mako:{}
});

pages/index.tsx

declare var foo: string;

export default function HomePage() {
  return (
    <div>
      {foo}
    </div>
  );
}

期望

页面显示 1

相关 issue

#1549

@Lemonnnnnnnnnnn
Copy link
Author

Lemonnnnnnnnnnn commented Oct 31, 2024

问题可能与 env_replacer.rs/EnvReplacer.visit_mut_expr 中的这段代码有关:

            // 先判断 env 中的变量名称,是否是上下文中已经存在的变量名称
            if ctxt.outer() != self.unresolved_mark {
                expr.visit_mut_children_with(self);
                return;
            }

因为 "declare var foo: string;" 导致上下文已经存在 foo ,所以未能注入全局变量

@stormslowly
Copy link
Member

@Lemonnnnnnnnnnn thanks a lot

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

Successfully merging a pull request may close this issue.

2 participants