thepassle / astro-firebase

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

TypeError: body is not async iterable #1

Open dperolio opened 2 years ago

dperolio commented 2 years ago

This is a repost by @noga-dev at https://github.com/thepassle/astro-firebase-demo/issues/1

I'm just posting it in the correct repo:

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

{

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 .

I've also added an example here: https://github.com/dperolio/immerse-testing

It is using the example SSR Astro demo (https://github.com/withastro/astro/tree/latest/examples/ssr) with astro-firebase added. You can see this issue when you try to deploy to Firebase and then run firebase functions:log