unjs / nitro

Next Generation Server Toolkit. Create web servers with everything you need and deploy them wherever you prefer.
https://nitro.unjs.io
MIT License
5.85k stars 493 forks source link

process.cwd() in `normalizeError` throws error for `vercel-edge` #759

Closed harlan-zw closed 4 months ago

harlan-zw commented 1 year ago

Environment

vercel-edge

Reproduction

https://github.com/harlan-zw/nuxt-edge-og-image-demo/tree/6f4e55caeb17b9699025b9c1bc8730f60bc0c1af

Describe the bug

TypeError: Wn.cwd is not a function
    at index.mjs:1:87695
    at index.mjs:1:88112
    at index.mjs:1:48649
    at index.mjs:1:221155

Looks like it's throwing an error, but because the error normalise itself has an error I can't see what the actual problem is.

Additional context

No response

Logs

No response

harlan-zw commented 1 year ago

Hm going to close temporarily until I rule out it not being something weird I've done

benjaminrobinet commented 1 year ago

@harlan-zw i'm having the exact same issue, did you find a fix on that ?

harlan-zw commented 1 year ago

Yeah so you likely have an error with your code but nitro fails to throw it properly. Can you provide some more details and I'll re-open the issue?

benjaminrobinet commented 1 year ago

Hard to tell as no errors are thrown... I have no problem using the vercel (non edge) preset. I am using the latest nuxt release, with all theses dependencies:


    "devDependencies": {
        "@nuxt/content": "^2.3.0",
        "@nuxt/image-edge": "^1.0.0-27840416.dc1ed65",
        "@nuxtjs/eslint-config-typescript": "^12.0.0",
        "@nuxtjs/strapi": "^1.6.3",
        "@types/rtree": "^1.4.28",
        "@types/three": "^0.146.0",
        "@types/vimeo__player": "^2.16.3",
        "autoprefixer": "^10.4.13",
        "eslint": "^8.28.0",
        "eslint-config-prettier": "^8.5.0",
        "husky": "^8.0.0",
        "lint-staged": "^13.0.3",
        "nuxt": "^3.0.0",
        "postcss": "^8.4.18",
        "prettier": "^2.7.1",
        "sass": "^1.56.1",
        "tailwindcss": "^3.2.3",
        "vite-plugin-glsl": "^1.0.1"
    },
    "dependencies": {
        "@studio-freight/lenis": "^0.2.28",
        "@use-gesture/vanilla": "^10.2.23",
        "@vimeo/player": "^2.18.0",
        "easings.scss": "^1.0.0-rc.0",
        "eventemitter3": "^4.0.7",
        "gsap": "npm:@gsap/shockingly@^3.11.4",
        "markdown-it": "^13.0.1",
        "quad-indices": "^2.0.1",
        "rtree": "^1.4.2",
        "three": "^0.146.0",
        "three-msdf-text": "github:leochocolat/three-msdf-text",
        "vite-svg-loader": "^3.6.0",
        "word-wrapper": "^1.0.7"
    },
benjaminrobinet commented 1 year ago

May the issue be related to https://github.com/nuxt/nuxt.js/issues/15513 ?

harlan-zw commented 1 year ago

I'll re-open but it may be related specifically to something we've done and not a Nitro issue exactly.

benjaminrobinet commented 1 year ago

@harlan-zw yes, I guess it is.. Looks like the issue si happening mostly in a nuxt context

pi0 commented 1 year ago

Do you have a more recent reproduction?

harlan-zw commented 1 year ago

I'll need to get back to you on that, feel free to close in the meantime.

To give some context though, the issue occurred when transpiling chrome-aws-lambda and puppeteer-core.

I added the following config to resolve some of the issues but got stuck on this last one.

import edgeChromium from 'chrome-aws-lambda'
import puppeteer from 'puppeteer-core'

export async function createBrowser() {
  return puppeteer.launch({
    args: edgeChromium.args,
    executablePath: await edgeChromium.executablePath,
    headless: true,
  })
}
// we need to mock some of the static requires from chrome-aws-lambda and puppeteer-core is okay though
['puppeteer', 'bufferutil', 'utf-8-validate'].forEach((name) => {
  // @ts-expect-error untyped
  nitroConfig.alias[name] = 'unenv/runtime/mock/proxy'
})
ThisIsAreku commented 1 year ago

I have the same issue with a fresh Nuxt 3.0 and deploying using NITRO_PRESET=vercel-edge.

Going to any non-existent page throw a 500 instead of a 404

It seems that with vercel-edge you can't use any nodejs api with edge functions : https://vercel.com/docs/concepts/functions/edge-functions/edge-functions-api

process.cwd() is called here : https://github.com/unjs/nitro/blob/v1.0.0/src/runtime/utils.ts#L44

vilhelmjosander commented 1 year ago

Same issue here with Nuxt 3.1 NITRO_PRESET=vercel-edge.

There's no problem or errors though if deploying with NITRO_PRESET=vercel.

rankjie commented 10 months ago

I see a fix was merged long ago, but with Nuxt 3.8.0, I still see this error: vercel_edge is still broken as calling process.cwd. I'm unsure if this is my issue or if this issue still exists.

pi0 commented 4 months ago

if still experiencing issues with latest versions, please feel free to open a fresh issue with reproduction 🙏🏼