question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Build fails when importing Firestore and using target serverless

See original GitHub issue

Bug 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

  1. package.json:
"dependencies": {
    "firebase": "^6.5.0",
    "next": "^9.0.5",
    "react": "^16.8.6",
    "react-dom": "^16.8.6"
  },
  1. 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 };
  1. next.config.js:
module.exports = {
  target: 'serverless',
};

Expected behavior

Build should succeed.

Screenshots

image

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:closed
  • Created 4 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
Timercommented, Sep 22, 2019

The difference is that serverless bundles node_modules and experimental-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-equivalent serverless output.


Should I need to consider something?

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 the node_modules folder! It’ll be required by your lambdas. Optimizing for a minimal node_modules folder will require additional work, but is handled automatically on ZEIT Now.

1reaction
timneutkenscommented, Sep 23, 2019

This is tracked somewhere else right now, so let’s close this issue 👍

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found