next.js: Production serverless build importing Firestore fails while including 'google/protobuf/api.proto'
Bug report
Describe the bug
When using import "firebase/firestore"
on a page with target: "serverless"
in next.config.js
, next build
fails with the following error:
> Build error occurred
Error: ENOENT: no such file or directory, open 'google/protobuf/api.proto'
To Reproduce
- Clone https://github.com/WestonThayer/bug-nextjs-firestore-grpc
npm install
npm run build
Expected behavior
The production build should succeed. It used to work in next@8.1.0
.
System information
- OS: macOS 10.14.6 (Mojave)
- Version of Next.js: 9.3.4
- Version of Node.js: v12.15.0
- Version of Firebase: 7.14.0
Additional context
- The build will succeed if you remove
target: "serverless"
fromnext.config.js
- Strangely,
next build
succeeds in the Zeit NOW environment. I see NOW is also using Nodev12.15.0
, so scratching my head as to what’s different
Seems like this is something that Next tried to get working in the past:
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 1
- Comments: 16 (13 by maintainers)
@Timer thx for the quick response. I will try to see with
serverless-next.js
then. When you mentioned to use the new target, do you meantarget: 'experimental-serverless-trace'
?Thanks for this excellent feedback. We’ll take it into account and rework the docs around this.
Regarding your questions above, deployments to ZEIT Now still use our builders (via zero config). Meaning
@now/next
still runs the show!This is the code that forces the target: https://github.com/zeit/now/blob/master/packages/now-next/src/create-serverless-config.ts
This is the code that wraps the build output for ZEIT Now: https://github.com/zeit/now/blob/master/packages/now-next/src/index.ts
Please remove
target: 'serverless'
, as it’s no longer needed to deploy to ZEIT Now.ZEIT Now no longer uses the
target: 'serverless'
option, instead, it auto configures a new target (serverless-trace
), which is why you see it work there.We created the new
serverless-trace
target to fix this exact set of problems!Correct,
experimental-serverless-trace
! This target still outputs the entrypoints in the format required for a serverless-type-platform, but requires you shipnode_modules
alongside it.