Babel runtime generator on build
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:
- Create project
- Add
firebase: 5.4.2,firebase-functions: 2.0.5,@babel/runtime: 7.0.0to the project. - Hook up firebase hosting to the project using the example
- Run the
firebase deploy --only hosting,functionsscript - Point your browser to your now hosted site
- See a
Error: could not handle the requesterror on the browser - 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.
@jthegedus
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)
});
}
Might be related to #5868
@planadecu you could also try importing regenerator-runtime/runtime.js
@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....}
Closing as this example has been recently updated and is working.
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.