Skip to content

请问报“ReferenceError: global is not defined”是什么原因? #124

Answered by zouyaoji
hkhenan asked this question in Q&A
Discussion options

You must be logged in to vote

@hkhenan 下次可以@我,才看到这个。
这个是正常的一般是在main.js或者index.html加一句:

main.ts

if (typeof (window as any).global === 'undefined') {
  (window as any).global = window
}

main.js

if (typeof window.global === 'undefined') {
  (window as any).global = window
}

index.html

  <body>
    <div id="app"></div>
    <script>
      var global = globalThis
    </script>
    <script type="module" src="/src/main.js"></script>
  </body>

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by zouyaoji
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants