我正在学习 Firebase 云功能,并在我的 中index.ts 文件夹我收到在 下突出显示的错误消息进口
我不知道这意味着什么以及如何解决它最糟糕的部分是相同的代码在 youtube 上的 firebase 教程视频中有效
这段代码有什么问题?
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!");
});
这是我的 tsconfig{
"compilerOptions": {
"module": "commonjs",
"noImplicitReturns": true,
"noUnusedLocals": true,
"outDir": "lib",
"sourceMap": true,
"strict": true,
"target": "es2017"
},
"compileOnSave": true,
"include": ["src"]
}
最佳答案
很可能,您的 tsconfig
中有错误文件。具体来说,您可能有一个明确的选项,称为 jsx
.我猜你实际上不需要为 Firebase 云函数解析 JSX,但我可能是错的。
这是我的 tsconfig
的一个例子对于 Firebase 云,它有效(当然,您可能需要稍微不同的选项):
{
"compilerOptions": {
"module": "commonjs",
"noImplicitReturns": true,
"noUnusedLocals": true,
"outDir": "lib",
"sourceMap": true,
"strict": true,
"target": "es2017",
},
"compileOnSave": true,
"include": [
"src"
]
}
也有可能是您的 src
目录不会导致您的 Typescript 源文件的位置。最后,VSCode 可能对您的 Typescript 设置做出了不正确的假设——这可能是因为您没有
tsconfig
文件或因为 VSCode 使用的 Typescript 版本与您的项目不同。在此处查看可能的解决方案:Problem with Visual Studio Code using "react-jsx" as jsx value with create-react-app引用此错误的其他一些资源:
关于reactjs - 解析错误 : Argument for '--jsx' option must be: 'preserve' , 'react-native' , 'react',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66091479/