nx: 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. This happens even with a clean app.

Expected Behavior

Regression. Expect NextJS app to build without error.

Steps to Reproduce

nx g @nrwl/next:app test-next-app nx build test-next-app –> error

This issue may not be prioritized if details are not provided to help us reproduce the issue.

Failure Logs

(replaced identifying path info with ...)

nx run test-next-app:build Browserslist: caniuse-lite is outdated. Please run: npx browserslist@latest --update-db info - Using external babel configuration from …/babel.config.json info - Using external babel configuration from …/apps/test-next-app/.babelrc info - Creating an optimized production build
info - Compiled successfully info - Collecting page data
[=== ] info - Generating static pages (0/2) Error occurred prerendering page “/404”. Read more: https://err.sh/next.js/prerender-error ReferenceError: regeneratorRuntime is not defined at …/dist/apps/test-next-app/.next/server/pages/_document.js:314:62 at …/dist/apps/test-next-app/.next/server/pages/_document.js:356:6 at Object.4D8t (…/dist/apps/test-next-app/.next/server/pages/_document.js:367:2) at webpack_require (…/dist/apps/test-next-app/.next/server/pages/_document.js:23:31) at Object.sf+I (…/dist/apps/test-next-app/.next/server/pages/_document.js:1189:18) at webpack_require (…/dist/apps/test-next-app/.next/server/pages/_document.js:23:31) at Module.Y7Z2 (…/dist/apps/test-next-app/.next/server/pages/_document.js:933:71) at webpack_require (…/dist/apps/test-next-app/.next/server/pages/_document.js:23:31) at Object.1 (…/dist/apps/test-next-app/.next/server/pages/_document.js:99:18) at webpack_require (…/dist/apps/test-next-app/.next/server/pages/_document.js:23:31)

Error occurred prerendering page “/”. Read more: https://err.sh/next.js/prerender-error ReferenceError: regeneratorRuntime is not defined at …/dist/apps/test-next-app/.next/server/pages/_document.js:314:62 at …/dist/apps/test-next-app/.next/server/pages/_document.js:356:6 at Object.4D8t (…/dist/apps/test-next-app/.next/server/pages/_document.js:367:2) at webpack_require (…/dist/apps/test-next-app/.next/server/pages/_document.js:23:31) at Object.sf+I (…/dist/apps/test-next-app/.next/server/pages/_document.js:1189:18) at webpack_require (…/dist/apps/test-next-app/.next/server/pages/_document.js:23:31) at Module.Y7Z2 (…/dist/apps/test-next-app/.next/server/pages/_document.js:933:71) at webpack_require (…/dist/apps/test-next-app/.next/server/pages/_document.js:23:31) at Object.1 (…/dist/apps/test-next-app/.next/server/pages/_document.js:99:18) at webpack_require (…/dist/apps/test-next-app/.next/server/pages/_document.js:23:31) Export encountered errors on following paths: / /404 [ ] info - Generating static pages (0/2)%

Environment

NX Report complete - copy this into the issue template

Node : 14.15.5 OS : darwin x64 npm : 6.14.11

nx : Not Found @nrwl/angular : Not Found @nrwl/cli : 11.5.1 @nrwl/cypress : 11.5.1 @nrwl/devkit : 11.5.1 @nrwl/eslint-plugin-nx : 11.5.1 @nrwl/express : 11.5.1 @nrwl/jest : 11.5.1 @nrwl/linter : 11.5.1 @nrwl/nest : Not Found @nrwl/next : 11.5.1 @nrwl/node : 11.5.1 @nrwl/react : 11.5.1 @nrwl/schematics : Not Found @nrwl/tao : 11.5.1 @nrwl/web : 11.5.1 @nrwl/workspace : 11.5.1 @nrwl/storybook : 11.5.1 @nrwl/gatsby : Not Found typescript : 4.0.6

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 34 (9 by maintainers)

Most upvoted comments

Note: this can be fixed in the raw test app by adding import 'regenerator-runtime/runtime'; as the first import of the NextJS app’s _document.tsx file

However, it doesn’t fix a larger app that imports libs. To fix that app, I needed to add that line to the top of all NextJS pages in use, as well as index.tsx and _app.tsx

@evanlk @cyrus-za (and whoever else): babel.config.json, add "plugins": ["@babel/plugin-transform-runtime"]

@kirjai I’ve just tried upgrading & migrating to the new major release Nx 12 and unfortunately the issue remains

Try to delete the folder dist from your project. It worked for me.

Ran into the same issue and isolated it down to async calls, fixed by including @babel/plugin-transform-runtime plugin in my Next application .babelrc

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

For more information see Babel Issue 9849


Edit: I’m on 11.6.1 and followed the previous advice of updating presets of the libraries to be web, but no luck

Edit: This works in a development environment but on deployment to Vercel the issue remains. Will update with any findings.

should be fixed in the next release. using a lib that uses the @nrwl/web/babel preset should now work

if the issue still persists - please provide a new repro, so we can look into it for you

I was able to reproduce the issue with a barebone version of my repo. Use https://github.com/evanlk/nxtest to reproduce. Also double checked to make sure the necessary .babelrc and babel.config.js files are in place. Let me know if you need anything else.

To reproduce the error use the following steps:

Serve up the test app nx serve test

Visit the following endpoint in your browser: http://localhost:4200/api/login

Monorepo is completely broke because of this issue. Tried the solution offered by @rplotkin, however it doesn’t work. It did work before, but for whatever reason this is no longer the case.