我正在尝试将我的react ssr部署到firebase函数,并且出现此错误,有人可以帮助我吗?
i functions: Watching "C:\Users\LucasPereira\Documents\Dev\Site\ProIT\frontend\functions" for Cloud Functions...
! C:\Users\LucasPereira\Documents\Dev\Site\ProIT\frontend\functions\src\assets\gif_pro_it.gif:1
GIF89a
SyntaxError: Invalid or unexpected token
at wrapSafe (internal/modules/cjs/loader.js:1167:16)
at Module._compile (internal/modules/cjs/loader.js:1215:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1272:10)
at Module.load (internal/modules/cjs/loader.js:1100:32)
at Function.Module._load (internal/modules/cjs/loader.js:962:14)
at Module.require (internal/modules/cjs/loader.js:1140:19)
at require (internal/modules/cjs/helpers.js:75:18)
at Object.<anonymous> (C:\Users\LucasPereira\Documents\Dev\Site\ProIT\frontend\functions\src\pages\Home\index.js:22:42)
at Module._compile (internal/modules/cjs/loader.js:1251:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1272:10)
! We were unable to load your functions code. (see above)
这是我的索引。tx(根)
import * as functions from 'firebase-functions';
import React from 'react';
import { renderToString } from 'react-dom/server';
import App from './src/App';
import express from 'express';
import fs from 'fs';
const index = fs.readFileSync(__dirname + '/index.html', 'utf-8');
const app = express();
app.get('**', (req, res)=>{
const html = renderToString(<App />);
const finalHtml = index.replace('<div id="root"></div>', `<div id="root">${html}</div>`);
res.set('Cache-Control', 'public, max-age=600, s-maxage=1200');
res.send(finalHtml);
})
export let ssrapp = functions.https.onRequest(app);
这是我的firebase.json
{
"hosting": {
"public": "dist",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"function": "ssrapp",
"destination": "/index.html"
}
]
},
"functions": {
"predeploy": {},
"source": "functions"
}
}
注意:我正在使用Express 4.17.1和节点版本14。 主机工作得很好,我只在功能上遇到问题
编辑:我更改了“ .gif”并继续显示错误,因此我决定将其删除,仅用于调试,好吧,错误继续出现在另一个图像(另一个PNG)上,该错误似乎出现在图像中< / p>
答案 0 :(得分:1)
您似乎正在尝试将* .gif图片导入某处(但未在提供的代码中);默认情况下,不支持导入GIF。
如果我是对的,那么您需要设置Webpack(或其替代方法)才能处理GIF文件的导入。