Closed Deleplace closed 6 hours ago
Hey @Deleplace, thanks for reaching out. I’m trying to reproduce the error you mentioned, but so far, I haven’t encountered any issues with running firebase serve --only hosting
. When visiting http://localhost:5000/ , a welcome page is displayed.
To help us narrow down what’s causing this, could you let us know which version of Node.js you’re using?
I’m using the ff to try and replicate this:
Thank you @aalej for this fast reply.
I edited the issue to mention I had freshly installed the Firebase CLI using brew.
I'm using Node.js v22.1.0
I suspect this specific bug would be easier to reproduce on Linux (filesystem stuff may vary).
It is possible the bug is in superstatic, where this line is dereferencing an fs stats time object which happened to be undefined
.
Thanks for the additional info, @Deleplace. TIL Node.js 22 was released. I tried switching to Node.js v22.1.0, and I was able to reproduce the error. Opening http://localhost:5000/ shows Unexpected error occurred.
.
Since I’m able to reproduce the issue on a macOS machine, I’m guessing that this could be caused by some changes in Node.js. Could you try temporarily switching to Node.js 20.x.x to see if it would workaround the issue?
Reading through https://nodejs.org/en/about/previous-releases, it looks like Node.js 20 is still the LTS version, while Node.js 22 is scheduled to become LTS around October 2024. I’ll discuss this with our engineering team to see what we could do to address this.
Awesome findings @aalej, this is working for me as well!
(via brew, not via nvm)
$ node -v
v22.1.0
$ brew install node@20
$ brew link --overwrite node@20
$ node -v
v20.13.1
$ firebase serve --only hosting
The Brew formula for firebase-cli currently "depends on node 22.2.0", which is maybe not the best for now.
I'm not sure of the implications, but it seems superstatic's package.json has
"engines": {
"node": "18 || 20"
}
while firebase-tools' package.json has
"engines": {
"node": ">=18.0.0 || >=20.0.0"
}
Thanks guys, facing the same issue, resolved after reverting node.js back to v20.
Also happened to me using node v22 in Debian. Downgraded to v20.
Same on Windows. Fixed by downgrading node from 22 to 20.
Same on Mac. As i learned on the comments here, fixed by downgrading from node 22 to 20
Hey all, I was also facing the same issue. In my case it was a pain to come back of NodeJs version, so literally what I did was to comment line 89 (it's basically a modified timestamp, not a big deal) and started working. Basically commented this line of code:
/usr/local/lib/node_modules/firebase-tools/node_modules/superstatic/lib/providers/fs.js:89:38
return {
// modified: stat.mtime.getTime(),
size: stat.size,
Sorry for only being able to come around to this now. In the short term, we likely will have to change firebase-tools's engines.node to indicate < 22, since we don't support that officially yet (since it's in active development, not stable). In the long term, we'll have to fix this in superstatic.
Downgrading node version from 22 to 20 and reinstalling firebase-tools after fixed it for me.
brew install node@20
brew unlink node
brew link node@20
npm install -g firebase-tools
firebase emulators:start
the same is happening to me on node20 (and node18 too)
nvm list
v9.11.2
v18.18.2
-> v20.10.0
default -> 20 (-> v20.10.0)
iojs -> N/A (default)
unstable -> N/A (default)
node -> stable (-> v20.10.0) (default)
stable -> 20.10 (-> v20.10.0) (default)
lts/* -> lts/iron (-> v20.10.0)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.17.0 (-> N/A)
lts/dubnium -> v10.24.1 (-> N/A)
lts/erbium -> v12.22.12 (-> N/A)
lts/fermium -> v14.21.3 (-> N/A)
lts/gallium -> v16.20.2 (-> N/A)
lts/hydrogen -> v18.18.2
lts/iron -> v20.10.0
% firebase serve --only hosting
(node:23755) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
i hosting[sdgsdhsdghsdghsfghs]: Serving hosting files from: public
✔ hosting[sdgsdhsdghsdghsfghs]: Local server: http://localhost:5002
TypeError: Cannot read properties of undefined (reading 'getTime')
at Responder.provider (/opt/homebrew/Cellar/firebase-cli/13.15.4/libexec/lib/node_modules/firebase-tools/node_modules/superstatic/lib/providers/fs.js:89:38)
at async Promise.all (index 0)
i hosting: 127.0.0.1 - - [26/Aug/2024:14:28:11 +0000] "GET / HTTP/1.1" 500 - "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36"
TypeError: Cannot read properties of undefined (reading 'getTime')
at Responder.provider (/opt/homebrew/Cellar/firebase-cli/13.15.4/libexec/lib/node_modules/firebase-tools/node_modules/superstatic/lib/providers/fs.js:89:38)
i hosting: 127.0.0.1 - - [26/Aug/2024:14:28:11 +0000] "GET /favicon.ico HTTP/1.1" 500 - "http://localhost:5002/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36"
@barii
% firebase serve --only hosting (node:23755) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
Looks like you're still running firebase
with Node 22.
For me, I had to install firebase a second time in the proper virtual environment.
For me, "brew install firebase-cli" automatically installs node 22.9 with it, how to get around that in venv? @eddieh
Personally I hate brew
and nvm
and both should be abandoned with extreme prejudice. I used the python virtual environment with nodeenv. It may be a bit more complex than other solutions, but it nicely contains everything in the project directory.
% python3 -m venv .env
% source .env/bin/activate
(.env) % pip install nodeenv
Then (not sure I picked the best node version, but it was a recent one with a point release):
(.env) % nodeenv --node=20.15.1 .nv20
(.env) % source .nv20/bin/activate
(.nv20) (.env) % npm install -g firebase-tools
Then
(.nv20) (.env) % firebase login
(.nv20) (.env) % firebase init
etc.
Maybe not the most elegant solution, but it is all in the project directory and the rest of my system is unchanged. No new version of node, firebase, or stupid shell functions (nvm, I'm looking at you).
I was facing the same issue on Windows, solved by downgrading to nodejs 20 using nvm. I used Chocolatey to install nvm, here are my steps:
Install nvm
using choco
:
choco install nvm
Install version 20:
nvm install 20
Change to new installed version:
nvm use 20
Verify current node version being used:
node -v
Restart the CMD and rerun firebase.
FYI - People using the latest Node LTS may start experiencing this issue as Node LTS just switched from v20 to v22 (https://github.com/nodejs/Release?tab=readme-ov-file#release-schedule).
(My tests just started to fail in Github actions as actions/setup-node@v4
was configured with node-version: lts/*
; forcing Node v20 by node-version: 20
resolved the issue.)
I have a manual solve that keeps the modified time.
You have to edit the file in question, and then on line 89 change from:
modified: stat.mtime.getTime(),
to
modified: stat.mtimeMs,
and thus the return statement will look like:
return {
modified: stat.mtimeMs,
size: stat.size,
etag: await fetchEtag(stat.pathname, stat),
stream: fs.createReadStream(stat.pathname),
};
And then recompile/redeploy.
This was just fixed in superstatic https://github.com/firebase/superstatic/releases/tag/v9.1.0
[REQUIRED] Environment info
firebase-tools:
13.8.3
Platform:
Ubuntu 22.04
[REQUIRED] Test case
No project code necessary for repro
[REQUIRED] Steps to reproduce
Then visit http://localhost:5000/ in browser
[REQUIRED] Expected behavior
In browser: a proper welcome page
[REQUIRED] Actual behavior
In browser: "Unexpected error occurred."