Skip to content

globalThis is not defined #7915

Answered by gookyn
leo-petrucci asked this question in Q&A
Apr 26, 2022 · 2 comments · 1 reply
Discussion options

You must be logged in to vote

I also have this problem, because there is no globalThis variable in lower version browsers, and the corresponding polyfill needs to be introduced:
https://github.com/zloirock/core-js#ecmascript-globalthis

In vite, it can be configured at @vitejs/plugin-legacy:

// vite.config.js

import legacy from '@vitejs/plugin-legacy';

export default defineConfig({
  // For production build environments only
  build: {
    target: 'es2015',
  },
  plugins: [
    // For production build environments only
    legacy({
      targets: ['chrome >= 64', 'edge >= 79', 'safari >= 11.1', 'firefox >= 67'],
      ignoreBrowserslistConfig: true,
      renderLegacyChunks: false,
      /**
       * Polyfills requi…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@javascripet
Comment options

Answer selected by bluwy
Comment options

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