firebase / firebase/firebase-tools

next.config.js bundle timeout deploys a broken build

Open
#6,193 10 comments 4 reactions 1 assignee Claimed by @leoortizz View on GitHub
integration: web frameworks Needs: Attention type: bug
Dominant language
TypeScript
Stars
4.5k
Forks
1.3k
Avg merge
1d 12h
Merged PRs (30d)
84

Description

https://github.com/firebase/firebase-tools/pull/5691 [introduced](https://github.com/firebase/firebase-tools/commit/e5981f2e0f40ff87139039cb5ac5004231f2e69f#diff-372d171b067c11f7dbdea434bc98b44c356278e71e0f1251758e4ca25517c0b8R459) a 10s timeout for bundling next.config.js. This bundling uses `npx esbuild next.config.js` command and it may timeout for a variety of reasons (most likely, network-related).

When this happens, the code fallbacks to copying next.config.js to the output. However, if next.config.js imports any other local file, copying next.config.js is not enough (as the other file needs to be copied as well).

This led to our CI silently deploying a broken build to production (sometimes) which then failed with hard to understand errors.

There are a couple of possible fixes, and I'm not sure which one is better:
- remove timeout for esbuild
- add `esbuild` to firebase-tools' dependencies, so bundling does not depend on network speed
- in fallback, copy all source files to output
- in fallback, stop the build

cc @jamesdaniels @leoortizz

### [REQUIRED] Environment info

**firebase-tools:** anything after https://github.com/firebase/firebase-tools/commit/e5981f2e0f40ff87139039cb5ac5004231f2e69f (11.30.0+)

**Platform:** any

### [REQUIRED] Test case

next.config.js:
```js
require('./other');

module.exports = {};
```

other.js:
```js
```

### [REQUIRED] Steps to reproduce

- flush npm/npx cache: `rm -rf "$(npm config get cache)/_npx"`
- run `env FIREBASE_CLI_EXPERIMENTS=webframeworks firebase deploy`
- loop until fails

### [REQUIRED] Expected behavior

It works

### [REQUIRED] Actual behavior

SSR is deployed but fails at runtime.

### Workaround
The simplest workaround is to add `esbuild` to your project's dependencies. This will cause `npx` to use project-installed version, so it can't timeout due to network

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.