我是 firebase 的新手,并试图从下面的视频中制作简单的 Cloud Functions + Express 示例来工作。
https://www.youtube.com/watch?v=LOeioOKUKI8
当我尝试从http://localhost:5000/timestamp提供我的 index.js时,出现以下错误。
无法获取 /{my-project-id}/us-central1/app/timestamp
在我的终端中,我得到以下输出。
? 创建了默认的“firebase-admin”实例!
i 函数:在 ~1秒内完成“应用程序”
[托管] 将 /timestamp 重写为http://localhost:5001/ {my-project-id}/us-central1/app 用于本地函数应用程序
但是如果我部署,它会按预期工作,并且会显示我的时间戳。
我当前的代码如下。
索引.js
var admin = require("firebase-admin");
admin.initializeApp();
const functions = require('firebase-functions');
const express = require('express');
const app = express();
app.get('/timestamp', (request, response) => {
response.send(`${Date.now()}`);
});
exports.app = functions.https.onRequest(app);
Run Code Online (Sandbox Code Playgroud)
firebase.json
{
"hosting": {
"public": "public",
"rewrites": [{
"source": "/timestamp",
"function": "app"
}],
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
]
} …Run Code Online (Sandbox Code Playgroud) node.js express firebase firebase-hosting google-cloud-functions
尝试将svg加载为ReactComponent时出现以下错误。
元素类型无效:需要一个字符串(对于内置组件)或一个类/函数(对于复合组件),但得到:未定义。您可能忘记了从定义文件中导出组件,或者可能混淆了默认导入和命名导入。
检查的渲染方法
Icon。
我正在使用带有typescript选项的create-react-app创建项目。如果我正确地理解了文档,那么我应该可以立即将svgs作为ReactComponent导入(自CRA2.0起)。但是奇怪的是,我对导入的组件没有定义。
添加图像,字体和文件·创建React App https://facebook.github.io/create-react-app/docs/adding-images-fonts-and-files#adding-svgs
当前正在使用以下软件包。
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-redux": "^6.0.1",
"react-router-dom": "^5.0.1",
"react-scripts": "^3.0.1",
"@types/node": "^12.0.0",
"@types/react": "^16.8.17",
"@types/react-dom": "^16.8.4",
"@types/react-redux": "^7.0.8",
"@types/react-router-dom": "^4.3.3",
Run Code Online (Sandbox Code Playgroud)
我的代码如下。
Icon.tsx
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-redux": "^6.0.1",
"react-router-dom": "^5.0.1",
"react-scripts": "^3.0.1",
"@types/node": "^12.0.0",
"@types/react": "^16.8.17",
"@types/react-dom": "^16.8.4",
"@types/react-redux": "^7.0.8",
"@types/react-router-dom": "^4.3.3",
Run Code Online (Sandbox Code Playgroud)
定制文件
import * as React from 'react';
import { ReactComponent as IconSvg } from './IconSvg.svg';
const Icon: React.FC<IconProps> = props => {
console.log(IconSvg); // undefined
return (<IconSvg />); …Run Code Online (Sandbox Code Playgroud)