regeneratorRuntime is not defined NextJS

See original GitHub issue

Issue

Build fails in nextjs due to regernatorRuntime is not defined from RecognitionManger.js. This is because the babel config which bundles the package isn’t conducive to eliminating regernatorRuntime which doesn’t work in server side rendering (SSR , which is what NextJS package specializes in).

Hacky Solution

I don’t know the solution, but my hacky solution was to copy the code from src into my repo and let the nextJS babel config ‘next/babel’ do the compilation without error. I tried https://github.com/babel/babel/issues/8829#issuecomment-456524916 but it did not solve the problem.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
iwgxcommented, Feb 21, 2021

Hi, I think import 'regenerator-runtime/runtime' didn’t work anymore

Edit: In my case now it works if it imported in _app.js instead of index.js

1reaction
JamesBrillcommented, Nov 21, 2020

Thanks for taking the time to prepare that example repo. I was able to reproduce the issue according to your instructions.

The solution that worked for me was to follow what others have done:

  • npm i --save regenerator-runtime
  • Import the Regenerator Runtime at the top of your JS index. i.e. put import 'regenerator-runtime/runtime' at the top of this file

I also tried installing the Babel runtime and transform plugin, plus the following .babelrc file:

{
  "presets": ["next/babel"],
  "plugins": ["@babel/plugin-transform-runtime"]
}

No change in result with that approach - not entirely sure why as I believe NextJS honours the root Babel config.

Anyway, I hope the manual import solution above is sufficient for you. I’m debating whether to add the Babel runtime as a peer dependency for this library - still researching the consequences of that.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Next App - ReferenceError: regeneratorRuntime is not defined ...
Current Behavior Migrated from 11.4.0 to 11.5.1 When building a NextJS app, a RegeneratorRuntime error is thrown and the app will not build....
Read more >
How to fix regeneratorRuntime is not defined?
I'm using next.js. I just installed the dependency regenerator-runtime and added import 'regenerator-runtime/runtime'; to the top of the ...
Read more >
regeneratorRuntime is not defined in React - Stack Overflow
I'm getting an error "Uncaught ReferenceError: regeneratorRuntime is not defined". Please help me to find out the error and how to resolve ...
Read more >
Uncaught ReferenceError: regeneratorRuntime is not defined ...
The solution I found (inspired by https://stephencharlesweiss.com/regenerator-runtime-not-defined/) was to import the @babel/plugin-transform-runtime NPM ...
Read more >
Parcel, how to fix the `regeneratorRuntime is not defined` error
Parcel, how to fix the `regeneratorRuntime is not defined` error ... HTML, CSS, JS, Tailwind, React, Next.js and much more! ✨.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found