所以我在TypeScript中使用Firebase的云函数
我想导入节点-获取如下所示:
import * as fetch from "node-fetch";但是它没有正确地导入:
当我尝试像这样使用fetch时:
fetch("https://payments.sandbox.braintree-api.com/graphql", {
method: "POST",
headers: {
"Authorization":
"bnIzdm5nZHlqempjNnQ3bTo0ZjMxYjQ5YjA2MDNjN2RkMjZhM2UyMGE3M2E3MWVlNw==",
"Braintree-Version": "2022-08-13",
"Content-Type": "application/json",
},
body: JSON.stringify({
query,
}),
})我有以下问题:
This expression is not callable.
Type 'typeof import(".../node_modules/node-fetch/@types/index")' has no call signatures.我想知道是否需要在运行之后添加一个依赖项:
npm install node-fetch因为在我的package.json
{
"name": "functions",
"scripts": {
"lint": "eslint --ext .js,.ts .",
"build": "tsc",
"build:watch": "tsc --watch",
"serve": "npm run build && firebase emulators:start --only functions",
"shell": "npm run build && firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"engines": {
"node": "16"
},
"main": "lib/index.js",
"dependencies": {
"firebase-admin": "^10.0.2",
"firebase-functions": "^3.18.0"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.12.0",
"@typescript-eslint/parser": "^5.12.0",
"eslint": "^8.9.0",
"eslint-config-google": "^0.14.0",
"eslint-plugin-import": "^2.25.4",
"firebase-functions-test": "^0.2.0",
"typescript": "^4.5.4"
},
"private": true
}不存在节点获取依赖关系。
如果是这样,我怎样才能解决我的问题呢?
发布于 2022-09-17 10:00:45
正如前面提到的这里,您必须在package.json中显式地添加此依赖项,因为node-fetch不是内置模块,需要安装。
您可以在本地机器上运行npm install node-fetch,但是并不是这样工作的。
要不然让我知道。
https://stackoverflow.com/questions/73517639
复制相似问题