firebase / firebase-tools

The Firebase Command Line Tools
MIT License
4.02k stars 937 forks source link

Cannot run firebase emulators:start with storage-resize-images extension #4554

Closed kuechlerm closed 2 years ago

kuechlerm commented 2 years ago

[REQUIRED] Environment info

firebase-tools: 10.9.2

Platform: Windows 10

[REQUIRED] Test case

Normal Firebase project

[REQUIRED] Steps to reproduce

I ran firebase ext:install firebase/storage-resize-images --local then firebase emulators:start

[REQUIRED] Expected behavior

Start emulators with the added extension

[REQUIRED] Actual behavior

Emulators do not start

[debug] [2022-05-17T18:04:16.706Z] ----------------------------------------------------------------------
[debug] [2022-05-17T18:04:16.708Z] Command:       C:\Program Files\nodejs\node.exe C:\Dev\my-project\node_modules\firebase-tools\lib\bin\firebase.js emulators:start
[debug] [2022-05-17T18:04:16.708Z] CLI Version:   10.9.2
[debug] [2022-05-17T18:04:16.708Z] Platform:      win32
[debug] [2022-05-17T18:04:16.708Z] Node Version:  v16.14.0
[debug] [2022-05-17T18:04:16.709Z] Time:          Tue May 17 2022 20:04:16 GMT+0200 (Mitteleuropäische Sommerzeit)
[debug] [2022-05-17T18:04:16.709Z] ----------------------------------------------------------------------
[debug] 
[debug] [2022-05-17T18:04:16.763Z] Object ".extensions" in "firebase.json" has unknown property: {"additionalProperty":"storage-resize-images"}
[debug] [2022-05-17T18:04:16.767Z] > command requires scopes: ["email","openid","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","https://www.googleapis.com/auth/cloud-platform"]
[debug] [2022-05-17T18:04:16.767Z] > authorizing via signed-in user (*****@gmail.com)
[debug] [2022-05-17T18:04:16.846Z] java version "17.0.2" 2022-01-18 LTS
Java(TM) SE Runtime Environment (build 17.0.2+8-LTS-86)

[debug] [2022-05-17T18:04:16.847Z] Java HotSpot(TM) 64-Bit Server VM (build 17.0.2+8-LTS-86, mixed mode, sharing)

[debug] [2022-05-17T18:04:16.875Z] Parsed Java major version: 17
[info] i  emulators: Starting emulators: auth, functions, firestore, hosting, storage, extensions {"metadata":{"emulator":{"name":"hub"},"message":"Starting emulators: auth, functions, firestore, hosting, storage, extensions"}}
[debug] [2022-05-17T18:04:16.899Z] [hub] writing locator at C:\Users\my-name\AppData\Local\Temp\hub-my-project.json
[debug] [2022-05-17T18:04:16.909Z] >>> [apiv2][query] GET https://firebase.googleapis.com/v1beta1/projects/my-project [none]
[debug] [2022-05-17T18:04:17.112Z] <<< [apiv2][status] GET https://firebase.googleapis.com/v1beta1/projects/my-project 200
[debug] [2022-05-17T18:04:17.112Z] <<< [apiv2][body] GET https://firebase.googleapis.com/v1beta1/projects/my-project {"projectId":"my-project","projectNumber":"***********","displayName":"my-project","name":"projects/my-project","resources":{"hostingSite":"my-project","storageBucket":"my-project.appspot.com","locationId":"europe-west3"},"state":"ACTIVE"}
[debug] [2022-05-17T18:04:17.113Z] Successfully read params from storage-resize-images.env
[debug] [2022-05-17T18:04:17.113Z] Error: ENOENT: no such file or directory, open 'C:\Dev\my-project\extensions\storage-resize-images.env.default'
[debug] [2022-05-17T18:04:17.113Z] Error: ENOENT: no such file or directory, open 'C:\Dev\my-project\extensions\storage-resize-images.env.***********'
[debug] [2022-05-17T18:04:17.114Z] Error: ENOENT: no such file or directory, open 'C:\Dev\my-project\extensions\storage-resize-images.env.my-project'
[debug] [2022-05-17T18:04:17.114Z] Error: ENOENT: no such file or directory, open 'C:\Dev\my-project\extensions\storage-resize-images.env.local'
[debug] [2022-05-17T18:04:17.114Z] >>> [apiv2][query] GET https://firebase.googleapis.com/v1beta1/projects/my-project/adminSdkConfig [none]
[debug] [2022-05-17T18:04:17.366Z] <<< [apiv2][status] GET https://firebase.googleapis.com/v1beta1/projects/my-project/adminSdkConfig 200
[debug] [2022-05-17T18:04:17.366Z] <<< [apiv2][body] GET https://firebase.googleapis.com/v1beta1/projects/my-project/adminSdkConfig {"projectId":"my-project","storageBucket":"my-project.appspot.com","locationId":"europe-west3"}
[debug] [2022-05-17T18:04:17.369Z] >>> [apiv2][query] GET https://firebase.googleapis.com/v1beta1/projects/my-project [none]
[debug] [2022-05-17T18:04:17.534Z] <<< [apiv2][status] GET https://firebase.googleapis.com/v1beta1/projects/my-project 200
[debug] [2022-05-17T18:04:17.534Z] <<< [apiv2][body] GET https://firebase.googleapis.com/v1beta1/projects/my-project {"projectId":"my-project","projectNumber":"***********","displayName":"my-project","name":"projects/my-project","resources":{"hostingSite":"my-project","storageBucket":"my-project.appspot.com","locationId":"europe-west3"},"state":"ACTIVE"}
[debug] [2022-05-17T18:04:17.536Z] >>> [apiv2][query] GET https://firebaseextensions.googleapis.com/v1beta/publishers/firebase/extensions/storage-resize-images/versions filter=&pageSize=100&pageToken=
[debug] [2022-05-17T18:04:18.299Z] <<< [apiv2][status] GET https://firebaseextensions.googleapis.com/v1beta/publishers/firebase/extensions/storage-resize-images/versions 200
[...] 
[debug] [2022-05-17T18:04:18.309Z] >>> [apiv2][query] GET https://firebaseextensions.googleapis.com/v1beta/publishers/firebase/extensions/storage-resize-images/versions/0.1.28 [none]
[debug] [2022-05-17T18:04:19.232Z] <<< [apiv2][status] GET https://firebaseextensions.googleapis.com/v1beta/publishers/firebase/extensions/storage-resize-images/versions/0.1.28 200
[...]
[info] i  extensions: Detected invalid source code for firebase/storage-resize-images@0.1.28, expected to find C:\Users\my-name\.cache\firebase\extensions\firebase\storage-resize-images@0.1.28\functions\node_modules {"metadata":{"emulator":{"name":"extensions"},"extension":{"ref":"firebase/storage-resize-images@0.1.28"},"message":"Detected invalid source code for firebase/storage-resize-images@0.1.28, expected to find C:\\Users\\my-name\\.cache\\firebase\\extensions\\firebase\\storage-resize-images@0.1.28\\functions\\node_modules"}}
[info] i  extensions: Starting download for firebase/storage-resize-images@0.1.28 source code... {"metadata":{"emulator":{"name":"extensions"},"extension":{"ref":"firebase/storage-resize-images@0.1.28"},"message":"Starting download for firebase/storage-resize-images@0.1.28 source code..."}}
[info] i  extensions: cache directory for firebase/storage-resize-images@0.1.28 already exists... {"metadata":{"emulator":{"name":"extensions"},"extension":{"ref":"firebase/storage-resize-images@0.1.28"},"message":"cache directory for firebase/storage-resize-images@0.1.28 already exists..."}}
[info] i  extensions: downloading https://storage.googleapis.com/firebase-mod-sources-prod/181466310919029d32f2df067e30058ad456e9eac0bb145e5481b1359a5758fc... {"metadata":{"emulator":{"name":"extensions"},"extension":{"ref":"firebase/storage-resize-images@0.1.28"},"message":"downloading https://storage.googleapis.com/firebase-mod-sources-prod/181466310919029d32f2df067e30058ad456e9eac0bb145e5481b1359a5758fc..."}}
[debug] [2022-05-17T18:04:19.238Z] >>> [apiv2][query] GET https://storage.googleapis.com/firebase-mod-sources-prod/181466310919029d32f2df067e30058ad456e9eac0bb145e5481b1359a5758fc 
[debug] [2022-05-17T18:04:19.268Z] <<< [apiv2][status] GET https://storage.googleapis.com/firebase-mod-sources-prod/181466310919029d32f2df067e30058ad456e9eac0bb145e5481b1359a5758fc 200
[debug] [2022-05-17T18:04:19.268Z] <<< [apiv2][body] GET https://storage.googleapis.com/firebase-mod-sources-prod/181466310919029d32f2df067e30058ad456e9eac0bb145e5481b1359a5758fc [stream]
[info] i  extensions: Downloaded to C:\Users\my-name\.cache\firebase\extensions\firebase\storage-resize-images@0.1.28... {"metadata":{"emulator":{"name":"extensions"},"extension":{"ref":"firebase/storage-resize-images@0.1.28"},"message":"Downloaded to C:\\Users\\my-name\\.cache\\firebase\\extensions\\firebase\\storage-resize-images@0.1.28..."}}
[info] i  emulators: Shutting down emulators. {"metadata":{"emulator":{"name":"hub"},"message":"Shutting down emulators."}}
[info] i  hub: Stopping emulator hub {"metadata":{"emulator":{"name":"hub"},"message":"Stopping emulator hub"}}
[debug] [2022-05-17T18:04:20.397Z] Error: spawnSync npm ENOENT
    at Object.spawnSync (node:internal/child_process:1111:20)
    at spawnSync (node:child_process:814:24)
    at ExtensionsEmulator.installAndBuildSourceCode (C:\Dev\my-project\node_modules\.pnpm\firebase-tools@10.9.2\node_modules\firebase-tools\lib\emulator\extensionsEmulator.js:113:58)
    at ExtensionsEmulator.downloadSource (C:\Dev\my-project\node_modules\.pnpm\firebase-tools@10.9.2\node_modules\firebase-tools\lib\emulator\extensionsEmulator.js:92:14)
    at async ExtensionsEmulator.ensureSourceCode (C:\Dev\my-project\node_modules\.pnpm\firebase-tools@10.9.2\node_modules\firebase-tools\lib\emulator\extensionsEmulator.js:81:17)
    at async ExtensionsEmulator.toEmulatableBackend (C:\Dev\my-project\node_modules\.pnpm\firebase-tools@10.9.2\node_modules\firebase-tools\lib\emulator\extensionsEmulator.js:133:30)
    at async Promise.all (index 0)
    at async ExtensionsEmulator.getExtensionBackends (C:\Dev\my-project\node_modules\.pnpm\firebase-tools@10.9.2\node_modules\firebase-tools\lib\emulator\extensionsEmulator.js:127:25)
    at async Object.startAll (C:\Dev\my-project\node_modules\.pnpm\firebase-tools@10.9.2\node_modules\firebase-tools\lib\emulator\controller.js:302:36)
    at async Command.actionFn (C:\Dev\my-project\node_modules\.pnpm\firebase-tools@10.9.2\node_modules\firebase-tools\lib\commands\emulators-start.js:28:35)
[error] 
[error] Error: An unexpected error has occurred.
joehan commented 2 years ago

Hey @kuechlerm , thanks for reporting this. Looking at the error logs, it seems like this is failing when we try to spawn a new process to npm install the extensions source code https://github.com/firebase/firebase-tools/blob/v10.9.2/src/emulator/extensionsEmulator.ts#L175

I'm not able to repro this on my Mac, so I suspect that this error is Windows only - possibly something similar to https://stackoverflow.com/questions/37125619/spawnsyncnpm-install-gives-error-spawnsync-npm-enoent

joehan commented 2 years ago

Looks like we probably need to use cross-spawn here instead to ensure that this works correctly on all platforms. Working on a fix to use that now.

kuechlerm commented 2 years ago

Hi @joehan thanks for the quick response. It would be great if you can fix it - I hope for the best ;) Thanks!

holasoycael commented 2 years ago

I'v the same issue and its work to me. Thanks!

I install global package cross-spawn and import from C:\Users\<...>\AppData\Roaming\nvm\v14.18.1\node_modules\firebase-tools\lib\emulator\extensionsEmulator.js and rename child_process_1 .

Thanks!!