Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build fails when importing Firestore and using target serverless #8797

Closed
Ferezoz opened this issue Sep 19, 2019 · 8 comments
Closed

Build fails when importing Firestore and using target serverless #8797

Ferezoz opened this issue Sep 19, 2019 · 8 comments

Comments

@Ferezoz
Copy link

Ferezoz commented Sep 19, 2019

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: #6073 (comment).

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.

@timneutkens
Copy link
Member

This is fixed through the experimental-serverless-trace right @Timer?

@Timer
Copy link
Member

Timer commented Sep 21, 2019

Yes, setting target: 'experimental-serverless-trace' should fix this issue.

FYI: @Ferezoz due to the way Firebase is designed, it's not compatible with target: 'serverless' -- we introduced a new mode to fix this (experimental-serverless-trace)!

@Timer
Copy link
Member

Timer commented Sep 21, 2019

We should look at de-experimentalizing this (because it's no longer experimental).

@Timer Timer added this to the 9.0.x milestone Sep 21, 2019
@Ferezoz
Copy link
Author

Ferezoz commented Sep 21, 2019

@Timer Thank you it worked!
Whats the difference between experimental-serverless-trace and serverless? Because I see the build emits lambdas as well. Should I need to consider something?

Edit: I see from #8246 that experimental-serverless-trace has a smaller bundle size than serverless?

@Timer
Copy link
Member

Timer commented 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.

@Ferezoz
Copy link
Author

Ferezoz commented Sep 23, 2019

Thank you for the explanation! 🙂 I'm using ZEIT Now so I don't need anything else.
The issue is fixed for me, should I close the ticket or maybe you want it open to track the de-experimentalization?

@timneutkens
Copy link
Member

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

@balazsorban44
Copy link
Member

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.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 31, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants