next.js icon indicating copy to clipboard operation
next.js copied to clipboard

Babel runtime generator on build

Open samosaboy opened this issue 8 years ago • 6 comments

Bug report

Describe the bug

Upon building the application using next build and deploying it to Firebase hosting following the firebase ssr example, the application fails to load and throws

{ Error: Cannot find module '@babel/runtime/regenerator' at Function.Module._resolveFilename (module.js:476:15) at Function.Module._load (module.js:424:25) at Module.require (module.js:504:17) at require (internal/module.js:20:19) at Object.@babel/runtime/regenerator (webpack:/external "@babel/runtime/regenerator":1:0) at __webpack_require__ (webpack:/webpack/bootstrap ad406904bc90fab2952f:21:0) at Object../pages/_app.tsx (/user_code/next/server/bundles/pages/_app.js:170:85) at __webpack_require__ (webpack:/webpack/bootstrap ad406904bc90fab2952f:21:0) at Object.0 (/user_code/next/server/bundles/pages/_app.js:4490:18) at __webpack_require__ (webpack:/webpack/bootstrap ad406904bc90fab2952f:21:0) code: 'MODULE_NOT_FOUND', sourceMapsApplied: true }

This only occurs on building of the application for production deployment. Serving the application locally results in no errors.

Adding @babel/runtime to package.json does not change the results and the bug persists.

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Create project
  2. Add firebase: 5.4.2, firebase-functions: 2.0.5, @babel/runtime: 7.0.0 to the project.
  3. Hook up firebase hosting to the project using the example
  4. Run the firebase deploy --only hosting,functions script
  5. Point your browser to your now hosted site
  6. See a Error: could not handle the request error on the browser
  7. Check firebase logs and see the above output (i.e. Error: Cannot find module '@babel/runtime/regenerator'

Expected behavior

We expect the website to load with no deployment issues related to SSR and Next.

System information

  • OS: OS X High Sierra 10.13.6
  • Version of Next.js: 6.1.1

This seems to be a persistent bug as pointed out in other issues here and here.

samosaboy avatar Sep 17 '18 01:09 samosaboy

@jthegedus

timneutkens avatar Sep 17 '18 11:09 timneutkens

I've solved the bug by just removing async to the getInitialProps function.

Before

Post.getInitialProps = async function(){
 ...
 values = await otherFunction();
 ...
 return values2;
}

After

Post.getInitialProps = function(){
 ...
  valuesPromise = otherFunction();

  return new Promise(function(resolve, reject) {
    valuesPromise.then(values =>{
      ...
      resolve(values2);
    }).catch(reject)
  });
}

planadecu avatar Sep 29 '18 11:09 planadecu

Might be related to #5868

@planadecu you could also try importing regenerator-runtime/runtime.js

NathanielHill avatar Feb 01 '19 14:02 NathanielHill

@planadecu, I tried with the promise way, the getInitialProps never get called on server.js, only when I added the async in front of getInitialProps, the build got back with

server.js:14 var _ref = _asyncToGenerator( /#PURE/regeneratorRuntime.mark(function _callee(ctx) { ReferenceError: regeneratorRuntime is not defined....}

xuemeigan avatar Mar 25 '19 01:03 xuemeigan

Closing as this example has been recently updated and is working.

Timer avatar Oct 10 '19 17:10 Timer

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

balazsorban44 avatar Jan 31 '22 02:01 balazsorban44