firebase / firebase-tools

The Firebase Command Line Tools
MIT License
4.01k stars 930 forks source link

firebase serve: TypeError: Cannot read properties of undefined (reading 'getTime') #7173

Open Deleplace opened 4 months ago

Deleplace commented 4 months ago

[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

$ uname -a
Linux my-desktop 6.5.0-18-generic #18~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Feb  7 11:40:03 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
$ brew install firebase-cli
$ firebase init
Select: Hosting
$ firebase serve --only hosting

Then visit http://localhost:5000/ in browser

[REQUIRED] Expected behavior

i  hosting[my-project]: Serving hosting files from: public
✔  hosting[my-project]: Local server: http://localhost:5000

In browser: a proper welcome page

[REQUIRED] Actual behavior

(node:104968) [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[my-project]: Serving hosting files from: public
✔  hosting[my-project]: Local server: http://localhost:5000

TypeError: Cannot read properties of undefined (reading 'getTime')
    at Responder.provider (/home/linuxbrew/.linuxbrew/Cellar/firebase-cli/13.8.3/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 - - [13/May/2024:14:34:57 +0000] "GET / HTTP/1.1" 500 - "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:123.0) Gecko/20100101 Firefox/123.0"

In browser: "Unexpected error occurred."

aalej commented 4 months 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.

image

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:

Deleplace commented 4 months ago

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.

aalej commented 4 months ago

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.

Deleplace commented 4 months ago

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.

Deleplace commented 4 months ago

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"
}
sushant3524 commented 4 months ago

Thanks guys, facing the same issue, resolved after reverting node.js back to v20.

gy-soft commented 4 months ago

Also happened to me using node v22 in Debian. Downgraded to v20.

ZYinMD commented 3 months ago

Same on Windows. Fixed by downgrading node from 22 to 20.

snagnever commented 3 months ago

Same on Mac. As i learned on the comments here, fixed by downgrading from node 22 to 20

juancho088 commented 3 months ago

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,
bkendall commented 3 months ago

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.

umrashrf commented 2 months ago

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
barii commented 1 month ago

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"
eddieh commented 2 weeks ago

@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.

hanspeteroliver commented 1 week ago

For me, "brew install firebase-cli" automatically installs node 22.9 with it, how to get around that in venv? @eddieh

eddieh commented 1 week ago

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).