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.
Steps to reproduce the behavior, please provide code snippets or a repository:
firebase: 5.4.2, firebase-functions: 2.0.5, @babel/runtime: 7.0.0 to the project.firebase deploy --only hosting,functions scriptError: could not handle the request error on the browserError: Cannot find module '@babel/runtime/regenerator'We expect the website to load with no deployment issues related to SSR and Next.
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.
Post.getInitialProps = async function(){
...
values = await otherFunction();
...
return values2;
}
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.
Most helpful comment
@jthegedus