thepassle / astro-firebase-demo

https://astro-firebase.web.app/
1 stars 0 forks source link

TypeError: body is not async iterable #1

Open noga-dev opened 2 years ago

noga-dev commented 2 years ago

Hitting this error when trying to reach the function via url. Otherwise just getting "Cannot GET /" when trying to reach the built Astro SSR

Astro 1.0.0-beta.73

root level package.json

{
  "name": "@example/basics",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "dev": "astro dev --experimental-ssr",
    "start": "astro dev --experimental-ssr",
    "build": "astro build --experimental-ssr",
    "preview": "firebase emulators:start",
    "deploy": "astro build --experimental-ssr && firebase deploy --only functions,hosting:main"
  },
  "type": "module",
  "devDependencies": {
    "astro": "^1.0.0-beta.73"
  },
  "dependencies": {
    "astro-firebase": "^0.0.3",
    "firebase-admin": "^11.0.0",
    "firebase-functions": "^3.20.1"
  }
}

functions package.json

{
  "type": "module",
  "engines": {
    "node": "16"
  },
  "dependencies": {
    "astro": "^1.0.0-beta.19",
    "astro-firebase": "^0.0.3",
    "firebase-admin": "^11.0.0",
    "firebase-functions": "^3.20.1"
  }
}

firebase.json

"target": "main",
      "public": "public/main/functions/client",
      "ignore": [
        "firebase.json",
        "**/.*",
        "**/node_modules/**"
      ],
      "rewrites": [
        {
          "source": "/",
          "destination": "handler"
        }
      ]

console

!  functions: TypeError: body is not async iterable
    at file:///D:/Source/challenges/jg/hack/public/main/functions/index.js:14654:33
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async runFunction (C:\Users\Agone\AppData\Roaming\nvm\v17.2.0\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:565:9)
    at async runHTTPS (C:\Users\Agone\AppData\Roaming\nvm\v17.2.0\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:591:5)
    at async C:\Users\Agone\AppData\Roaming\nvm\v17.2.0\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:534:17
!  Your function was killed because it raised an unhandled error.

index.js lines 14633-14662

const createExports = (manifest) => {
  const app = new App(manifest);

  const handler = functions.https.onRequest(async (req, res) => {
    const url = req.protocol + '://' + req.get('host') + req.originalUrl;
    const request = new Request(url, {
      method: req.method,
      headers: new Headers(req.headers)
    });

    if (!app.match(request)) {
      return {
        statusCode: 404,
        body: 'Not found',
      };
    }

    const { status, headers, body } = await app.render(request);

    res.writeHead(status, Object.fromEntries(headers.entries()));
    if (body) {
      for await (const chunk of body) {
        res.write(chunk);
      }
    }
    res.end();
  });

  return { handler };
};

I just realized I should have raised this issue in https://github.com/thepassle/astro-firebase but I guess I can keep this here anyway. Let me know if I should open it on that other repo, @thepassle .

dperolio commented 2 years ago

+1... Really need a fix for this. I have attempted it, but no luck.