gpt4 book ai didi

reactjs - Typescript 中的 React + Firebase 云函数无法部署

转载 作者:行者123 更新时间:2023-12-04 00:00:04 24 4
gpt4 key购买 nike

我是我的项目,我想使用

  • 在 Firebase 托管上托管的 Typescript 中的 React 应用程序
  • Firestore
  • Typescript 中的 Firebase 函数

  • 我在部署时遇到错误。很容易重现(现在跳过 firestore 和 firebase 托管初始化)
    yarn create react-app sample-app
    cd sample-app
    firebase init
    (select functions by marking a box interactively)
    (select typescript by marking a box interactively)
    (uncomment in functions/src/index.ts)
    函数/src/index.ts 是
    import * as functions from 'firebase-functions';

    // Start writing Firebase Functions
    // https://firebase.google.com/docs/functions/typescript
    export const helloWorld = functions.https.onRequest((request, response) => {
    functions.logger.info("Hello logs!", {structuredData: true});
    response.send("Hello from Firebase!");
    });
    然后部署失败
    firebase deploy

    === Deploying to 'myproject'...

    i deploying functions
    Running command: npm --prefix "$RESOURCE_DIR" run lint

    > functions@ lint /Users/username/sample-app/functions
    > tslint --project tsconfig.json

    Running command: npm --prefix "$RESOURCE_DIR" run build

    > functions@ build /Users/username/sample-app/functions
    > tsc

    ../node_modules/@types/testing-library__react/index.d.ts:13:49 - error TS7016: Could not find a declaration file for module '@testing-library/dom'. '/Users/username/sample-app/node_modules/@testing-library/dom/dist/index.js' implicitly has an 'any' type.
    Try `npm install @types/testing-library__dom` if it exists or add a new declaration (.d.ts) file containing `declare module '@testing-library/dom';`

    13 import { queries, Queries, BoundFunction } from '@testing-library/dom';
    ~~~~~~~~~~~~~~~~~~~~~~

    ../node_modules/@types/testing-library__react/index.d.ts:16:15 - error TS7016: Could not find a declaration file for module '@testing-library/dom'. '/Users/username/sample-app/node_modules/@testing-library/dom/dist/index.js' implicitly has an 'any' type.
    Try `npm install @types/testing-library__dom` if it exists or add a new declaration (.d.ts) file containing `declare module '@testing-library/dom';`

    16 export * from '@testing-library/dom';
    ~~~~~~~~~~~~~~~~~~~~~~


    Found 2 errors.

    npm ERR! code ELIFECYCLE
    npm ERR! errno 2
    npm ERR! functions@ build: `tsc`
    npm ERR! Exit status 2
    npm ERR!
    npm ERR! Failed at the functions@ build script.
    npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

    npm ERR! A complete log of this run can be found in:
    npm ERR! /Users/username/.npm/_logs/2020-08-04T06_14_06_195Z-debug.log

    Error: functions predeploy error: Command terminated with non-zero exit code2
    即使在我做了之后 npm install @types/testing-library__dom在 root 和 functions/中,部署失败。
    和根目录有
    ls
    README.md firebase.json functions node_modules package.json public src tsconfig.json yarn.lock
    欢迎任何想法。

    最佳答案

    你能试试这个解决方案是否适合你吗?
    https://stackoverflow.com/a/49309428/1673761

    add this line to tsconfig within the functions folder:


    {                                                                                       
    "compilerOptions": {
    ...
    "typeRoots": [
    "node_modules/@types",
    ],
    ...
    }

    This is part of "compilerOptions" block worked for me

    关于reactjs - Typescript 中的 React + Firebase 云函数无法部署,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63241285/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com