Build fails when importing Firestore and using target serverless
See original GitHub issueBug report
Describe the bug
Build fails when importing Firestore
and using target: 'serverless'
even after upgrading next
to at least version 9.0.4 as mentioned here: https://github.com/zeit/next.js/issues/6073#issuecomment-467589586.
Module not found: Can't resolve 'memcpy' in '.../node_modules/bytebuffer/dist'
To Reproduce
- package.json:
"dependencies": {
"firebase": "^6.5.0",
"next": "^9.0.5",
"react": "^16.8.6",
"react-dom": "^16.8.6"
},
- firebase.js:
import firebase from 'firebase/app';
import 'firebase/firestore';
const config = {
...
};
const firebaseApp = !firebase.apps.length
? firebase.initializeApp(config)
: firebase.app();
const firestore = firebaseApp.firestore();
export default firebaseApp;
export { firestore };
- next.config.js:
module.exports = {
target: 'serverless',
};
Expected behavior
Build should succeed.
Screenshots
System information
- Version of Next.js: 9.0.5
- Version of firebase: 6.5.0
Additional context
It works on local next dev
.
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (6 by maintainers)
Top Results From Across the Web
Build fails when importing Firestore and using target serverless
Build fails when importing Firestore and using target : 'serverless' even after upgrading next to at least version 9.0.4 as mentioned here: #6073 ......
Read more >Unable to build NextJS app locally when using Firestore
I'm building a web app and am fetching data from the Firestore both on the client and on the server with getStaticProps and...
Read more >Get started with Cloud Firestore - Firebase
Cloud Firestore and App Engine: You can't use both Cloud Firestore and Cloud Datastore in the same project, which might affect apps using...
Read more >Troubleshooting build errors | Cloud Build Documentation
Build triggers use the Cloud Build service account to create a build. The error above indicates that the Cloud Build service account is...
Read more >Developing a Serverless Web Application Completely on ...
Building a serverless web application with Firebase and NodeJS without downloading ... import { getFirestore } from "firebase/firestore";
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The difference is that
serverless
bundlesnode_modules
andexperimental-serverless-trace
does not!Bundling
node_modules
is very problematic for server-side code, as it may rely on compiled binaries (like gRPC for Firestore) or reading certain files from the file-system (fs.readFileSync()
). Bundling these modules means the files they’re looking for no longer exist at the same path – so it’s generally not safe to do so.This problem doesn’t exist for client-side code because there’s no concept of external files in the browser.
All things considered (ready-to-go
.zip
lambdas),experimental-serverless-trace
output size should be identical or slightly smaller than a functioning-equivalentserverless
output.If you’re deploying to ZEIT Now: Nope! We automatically handle and optimize lambda size for you.
If you’re self-hosting via
next start
: Don’t delete thenode_modules
folder! It’ll be required by your lambdas. Optimizing for a minimalnode_modules
folder will require additional work, but is handled automatically on ZEIT Now.This is tracked somewhere else right now, so let’s close this issue 👍