简体   繁体   中英

“Invalid or unexpected token” while deploying to firebase functions

I was trying to deploy my react ssr to firebase functions and this error appeared to me, can someone help me?

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)

This is my index.tx(root)

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);

This is my firebase.json

{
  "hosting": {
    "public": "dist",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "**",
        "function": "ssrapp",
        "destination": "/index.html"
      }
    ]
  },
  "functions": {
    "predeploy": {},
    "source": "functions"
  }
}

NOTE: I'm using express 4.17.1, and node version 14. The host is working very well i'm only having problem with functions

EDIT: I change the ".gif" and it continues showing error, so I decided to remove it, only for debug, well, the error continues to another image(another PNG), the error appears to be in images

It looks like you're trying to import a *.gif image somewhere (but not in the provided code); by default, importing GIFs is not supported.

If I'm correct, then you need to setup Webpack (or its alternatives) in order to handle imports of GIF files.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM