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

Vite throws 'Uncaught ReferenceError: regeneratorRuntime is not defined' #227

Closed
dd-jonas opened this issue Feb 25, 2022 · 13 comments · Fixed by #236
Closed

Vite throws 'Uncaught ReferenceError: regeneratorRuntime is not defined' #227

dd-jonas opened this issue Feb 25, 2022 · 13 comments · Fixed by #236

Comments

@dd-jonas
Copy link

Describe the bug
Uncaught ReferenceError: regeneratorRuntime is not defined when using react-location with Vite.

To Reproduce
Steps to reproduce the behavior:

  1. yarn create vite --template react-ts
  2. yarn
  3. yarn add @tanstack/react-location
  4. Replace App.tsx with code below
  5. yarn dev
import { ReactLocation, Router } from '@tanstack/react-location';

const location = new ReactLocation();

function App() {
  return (
    <Router location={location} routes={[{ path: '/' }]}>
      <h1>Title</h1>
    </Router>
  );
}

export default App;

Screenshots
Console error

Desktop (please complete the following information):

  • OS: Windows 10 64-bits
  • Browser: Chrome
  • Version: 98.0.4758.102
@danielbayerlein
Copy link

See #220. Should be fixed with #223.

@ruisaraiva19
Copy link
Contributor

ruisaraiva19 commented Mar 6, 2022

This still happens with version 3.6.5 which has #223.

Dependencies

  • Vite: 2.8.6
  • @tanstack/react-location: 3.6.5

Only works when using version react-location <= 3.3.4

@danielbayerlein
Copy link

The problem still exists with version 3.7.0.

@hugooliveirad
Copy link
Contributor

Issues are not related. To fix this one you will have to use the regenerator-runtime library and call it from your main file.

See this discussion on a similar issue with amplify-js aws-amplify/amplify-js#8514 (comment)

Here, I solved it by installing regenerator-runtime (yarn add regenerator-runtime) and adding import 'regenerator-runtime' to the top-level JavaScript file in my application (main.tsx in my case).

@ruisaraiva19
Copy link
Contributor

@HugoBDev that's for the suggestion. Importing regenerator-runtime fixes the issue.

Maybe this is something that can be added to the docs.

@dd-jonas
Copy link
Author

I have tried out react-location a while back with vite and didn't encounter this issue. What changes that made importing regenerator-runtime necessary now?

@bhbs
Copy link
Contributor

bhbs commented Mar 17, 2022

This issue was fixed with #236
Try the latest version 👍 v3.7.2

@reintroducing
Copy link
Contributor

reintroducing commented Apr 28, 2022

Still happening for me in v3.7.4.
Screen Shot 2022-04-28 at 1 48 25 PM

EDIT: Sorry, got my tanstack modules mixed up, thats actually calling react-table useAsyncDebounce.

@unional
Copy link

unional commented Jan 13, 2023

Still happening in vite 4.0.2

@elmapaul
Copy link

elmapaul commented Jul 2, 2023

Still happening in vite 4.3.9

@fruitbang
Copy link

It is still there! vite 4.4.0

@datnguyennnx
Copy link

datnguyennnx commented Sep 11, 2023

Try this way:
pnpm install vite-plugin-babel @vitejs/plugin-legacy

Then copy this code to vite.config.ts

import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import legacy from '@vitejs/plugin-legacy'
import babel from 'vite-plugin-babel'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    react(), 
    legacy({
      targets: ['defaults', 'not IE 11'],
      additionalLegacyPolyfills: ['regenerator-runtime/runtime'],
    }),
    babel({
      babelConfig: {
          babelrc: false,
          configFile: false,
          plugins: ['@babel/plugin-transform-runtime'],
      }
  })
  ],
})

@vishal4kingsbridge
Copy link

When using React Table, if your code uses async/await syntax, you need to introduce the regenerator-runtime library into the project.

  1. You can install the regenerator-runtime library via npm and then include it in your code:
    npm install --save regenerator-runtime

  2. Introduce it in your entry file, such as index.js or main.js
    import 'regenerator-runtime/runtime'

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.