Облачные функции React + Firebase в Typescript не развертываются - PullRequest
1 голос
/ 04 августа 2020

Im мой проект, я хотел бы использовать

  • приложение React в Typescript, размещенном на хостинге Firebase
  • Firestore
  • Функции Firebase в Typescript

Столкнулся с ошибкой при развертывании. Легко воспроизвести (теперь пропустите инициализацию хостинга firestore и firebase)

yarn create react-app sample-app
cd sample-app
firebase init
check functions interactively
check typescript interactively
uncomment functions/src/index.ts

functions / src / index.ts is

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 /, развертывание завершилось неудачно.

и root каталог имеет

ls
README.md     firebase.json functions     node_modules  package.json  public        src           tsconfig.json yarn.lock

Любая идея приветствуется.

1 Ответ

3 голосов
/ 04 августа 2020

Можете ли вы попробовать, работает ли это решение для вас?

{ ссылка }

добавьте эту строку в tsconfig в папке функций:

"typeRoots": [
  "node_modules/@types"
],

Это часть блока compilerOptions, который работал у меня

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...