在云功能教程中的模拟器中,firestore不起作用

问题描述

我遵循了教程https://firebase.google.com/docs/functions/get-started(从头开始两次),而Firestore是空白的。

请注意,在需要进行o初始化Firestore的步骤3.3中,我按照控制台中的步骤进行了操作,并在网络上对其进行了初始化

firebase模拟器套件http://localhost:4000/logs中的日志

12:19:34 I ui Emulator UI logging to ui-debug.log 12:19:35 I functions Watching "/home/kirill/try-function-d8787/functions" for Cloud Functions... 
12:19:36 I functions http function initialized (http://localhost:5001/try-function-d8787/us-central1/addMessage). 
12:19:36 I functions firestore function initialized. 12:19:36 I

┌───────────────────────────────────────────────────────────────────────┐ 
│ ✔  All emulators ready! View status and logs at http://localhost:4000 │ 
└───────────────────────────────────────────────────────────────────────┘

┌───────────┬────────────────┬─────────────────────────────────┐ 
│ Emulator  │ Host:Port      │ View in Emulator UI             │ 
├───────────┼────────────────┼─────────────────────────────────┤ 
│ Functions │ localhost:5001 │ http://localhost:4000/functions │ 
├───────────┼────────────────┼─────────────────────────────────┤ 
│ Firestore │ localhost:8080 │ http://localhost:4000/firestore │ 
└───────────┴────────────────┴─────────────────────────────────┘   

Other reserved ports: 4400,4500

Issues? Report them at https://github.com/firebase/firebase-tools/issues and attach the*-debug.log files.   

12:22:34 I function[addMessage] Beginning execution of "addMessage" 
12:22:35 I function[addMessage] Finished "addMessage" in ~1s 
12:22:35 I function[makeUppercase] Beginning execution of "makeUppercase" 
12:22:36 I function[makeUppercase] {   "severity": "INFO","message": "Uppercasing Md0HKOGNHNVo7pk9hhbq uppercaseme" } 
12:22:36 I function[makeUppercase] Finished "makeUppercase" in ~1s

firestore标签

enter image description here

终端日志(不确定如何正确发布):

    ~ ❯❯❯ cd try-function-d8787 ~/try-function-d8787 ❯❯❯ firebase login Already logged in as [email protected] ~/try-function-d8787 ❯❯❯ firebase init firestore
            ✘ 1                                                                                                                                                                                                                                                                                                                                                                                                  ######## #### ########  ######## ########     ###     ######  ########                                                                                                                              ##        ##  ##     ## ##       ##     ##  ##   ##  ##       ##                                                                                                                                    ######    ##  ########  ######   ########  #########  ######  ######                                                                                                                                ##        ##  ##    ##  ##       ##     ## ##     ##       ## ##                                                                                                                                    ##       #### ##     ## ######## ########  ##     ##  ######  ########
    
    You're about to initialize a Firebase project in this directory:
    
      /home/kirill/try-function-d8787
    
    
    === Project Setup
                                                                                                                                                                                                        First,let's associate this project directory with a Firebase project. You can create multiple project aliases by running firebase use --add,but for Now we'll just set up a default project.
    
    ? Please select an option: Use an existing project                     ? Select a default Firebase project for this directory: try-function-d8787 (try-function)                                      i  Using project try-function-d8787 (try-function)
                                                                                                                                                                                                        === Firestore Setup
                                                                                                                                                                                                        Firestore Security Rules allow you to define how and when to allow     requests. You can keep these rules in your project directory           and publish them with firebase deploy.
                                                                                                                                                                                                        ? What file should be used for Firestore Rules? firestore.rules        Firestore indexes allow you to perform complex queries while           maintaining performance that scales with the size of the result        set. You can keep index deFinitions in your project directory          and publish them with firebase deploy.                                 ? What file should be used for Firestore indexes? firestore.indexes.json                                                 i  Writing configuration info to firebase.json...                      i  Writing project @R_263_4045@ion to .firebaserc... i  Writing gitignore file to .gitignore...
                                                                                                                                                                                                        ✔  Firebase initialization complete! ~/try-function-d8787 ❯❯❯ firebase init functions
                                                                                                                                                                                                  [3/87]     ######## #### ########  ######## ########     ###    
    ######  ########                                                                                                                              ##        ##  ##     ## ##       ##     ##  ##   ##  ##       ##                                                                                                                                    ######    ##  ########  ######   ########  #########  ######  ######                                                                                                                                ##        ##  ##    ##  ##       ##     ## ##     ##       ## ##                                                                                                                                    ##       #### ##     ## ######## ########  ##     ##  ######  ########
    
    You're about to initialize a Firebase project in this directory:
    
      /home/kirill/try-function-d8787
    
    Before we get started,keep in mind:
    
      * You are initializing in an existing Firebase project directory
    
    
    === Project Setup
    
    First,but for Now we'll just set up a default project.
    
    i  .firebaserc already has a default project,using try-function-d8787.
    
    === Functions Setup
    
    A functions directory will be created in your project with a Node.js   package pre-configured. Functions can be deployed with firebase deploy.
    
    ? What language would you like to use to write Cloud Functions? JavaScript                                                             ? Do you want to use ESLint to catch probable bugs and enforce style? Yes                                                                    ✔  Wrote functions/package.json ✔  Wrote functions/.eslintrc.json ✔  Wrote functions/index.js ✔  Wrote functions/.gitignore ? Do you want to install dependencies with npm Now? Yes
    
    > [email protected] postinstall /home/kirill/try-function-d8787/functions/node_modules/protobufjs     
    > node scripts/postinstall
    
    npm notice created a lockfile as package-lock.json. You should commit this file.                                                             added 360 packages from 263 contributors and audited 360 packages in
    11.852s
    
    34 packages are looking for funding   run `npm fund` for details
    
    found 0 vulnerabilities
    
    
    i  Writing configuration info to firebase.json... i  Writing project @R_263_4045@ion to .firebaserc...
    
    ✔  Firebase initialization complete! ~/try-function-d8787 ❯❯❯ ls functions  firebase.json  firestore.indexes.json  firestore.rules      ~/try-function-d8787 ❯❯❯ cd functions ~/t/functions ❯❯❯ vim index.js ~/t/functions ❯❯❯ cd .. ~/try-function-d8787 ❯❯❯ firebase emulators:start i  emulators: Starting emulators: functions,firestore ⚠  functions: The following emulators are not running,calls to these services from the Functions emulator will affect production: database,hosting,pubsub ✔  functions: Using node@10 from host. i  firestore: Firestore Emulator logging to firestore-debug.log                      i  ui: Emulator UI logging to ui-debug.log i  functions: Watching "/home/kirill/try-function-d8787/functions" for Cloud Functions...     ✔  functions[addMessage]: http function initialized (http://localhost:5001/try-function-d8787/us-central1/addMessage). ✔  functions[makeUppercase]: firestore function initialized.
    
    ┌───────────────────────────────────────────────────────────────────────┐ │ ✔  All emulators ready! View status and logs at http://localhost:4000 │                                                └───────────────────────────────────────────────────────────────────────┘
    
    ┌───────────┬────────────────┬─────────────────────────────────┐       │ Emulator  │ Host:Port      │ View in Emulator UI             │       ├───────────┼────────────────┼─────────────────────────────────┤       │ Functions │ localhost:5001 │ http://localhost:4000/functions │       ├───────────┼────────────────┼─────────────────────────────────┤       │ Firestore │ localhost:8080 │ http://localhost:4000/firestore │       └───────────┴────────────────┴─────────────────────────────────┘       Other reserved ports: 4400,4500
    
    Issues? Report them at https://github.com/firebase/firebase-tools/issues and attach the
    *-debug.log files.
    
    i  functions: Beginning execution of "addMessage" i  functions: Finished "addMessage" in ~1s i  functions: Beginning execution of "makeUppercase"
    >  {"severity":"INFO","message":"Uppercasing Md0HKOGNHNVo7pk9hhbq uppercaseme"}                                                          i  functions: Finished "makeUppercase" in ~1s

解决方法

Firebase模拟器不适用于WSL2 right now。我通过在Windows安装nodejs / npm的git-bash控制台中解决了这个问题