Closed remihuigen closed 2 months ago
I’m having the same problem when running npx wrangler pages dev dist/
. In the NuxtHub admin, I get this error:
Error: Failed to publish your Function. Got error: Uncaught ReferenceError: global is not defined
at chunks/runtime.mjs:1:30924
In my project, I am only using Supabase, NuxtUI, NuxtHub and Pinia. And I have enabled compatibilityVersion: 4
.
{
"name": "new-app",
"type": "module",
"private": true,
"packageManager": "pnpm@9.10.0",
"scripts": {
"build": "nuxt build",
"dev": "nuxt dev",
"generate": "nuxt generate",
"postinstall": "nuxt prepare",
"preview": "nuxt preview"
},
"dependencies": {
"@antfu/eslint-config": "^3.5.1",
"@nuxt/eslint": "^0.5.7",
"@nuxt/ui": "^2.18.4",
"@nuxthub/core": "^0.7.12",
"@nuxtjs/supabase": "^1.4.0",
"@pinia/nuxt": "^0.5.4",
"@vueuse/router": "^11.0.3",
"camelcase-keys": "^9.1.3",
"dayjs": "^1.11.13",
"eslint-plugin-tailwindcss": "^3.17.4",
"nuxt": "^3.13.1",
"pagedjs": "^0.4.3",
"snakecase-keys": "^8.0.1",
"vue": "^3.5.4",
"vue-router": "^4.4.4",
"zod": "^3.23.8"
},
"devDependencies": {
"sass": "^1.78.0",
"wrangler": "^3.76.0"
}
}
export default defineNuxtConfig({
future: {
compatibilityVersion: 4,
},
modules: [
'@nuxt/eslint',
'@nuxthub/core',
'@nuxt/ui',
'@nuxtjs/supabase',
'@pinia/nuxt',
],
eslint: {
config: {
standalone: false,
stylistic: true,
typescript: true,
},
},
colorMode: {
preference: 'light',
},
supabase: {
types: '~/types/database.types.ts',
},
compatibilityDate: '2023-09-10',
devtools: { enabled: true },
})
@adamkasper this is not related to the main issue, see https://github.com/nuxt-hub/core/issues/261#issuecomment-2343229143 (should be fixed in upcoming Nuxt release)
Let me have a look @remihuigen
Why do you need to run the npx wrangler pages dev dist/
command @remihuigen ?
Sorry, I wasn't clear. Got this error in local dev, not in production
Was debugging as described on https://hub.nuxt.com/docs/recipes/debug
To confirm: I'm not getting the error in production
I see, well the debugging is not perfect yes as I don't provide the wrangler.toml
, let me track this on https://github.com/nuxt-hub/cli/issues/22
Sure, no problem.
Didn't get these errors though when following https://hub.nuxt.com/docs/recipes/debug with v0.7.9, so i'd thought a new issue was in order :)
The issue here is that the preview should be running in nodejs_compat
mode which is enabled by default when you deploy it in production.
For local workers you get this warning first while compiling, and then on runtime you get the above error:
[WARNING] The package "node:async_hooks" wasn't found on the file system but is built into node.
Your Worker may throw errors at runtime unless you enable the "nodejs_compat" compatibility flag.
Refer to https://developers.cloudflare.com/workers/runtime-apis/nodejs/ for more details. Imported
from:
Faced the same issue yesterday while trying to preview the build locally. Not sure how to enable the compat mode locally.
As a workaround you can create a wrangler.toml
at the root of your project (will be used only for the preview)
compatibility_flags = ["nodejs_compat_v2"]
Will work on https://github.com/nuxt-hub/cli/issues/22 to fix this
Alright it's live! https://hub.nuxt.com/changelog/nuxthub-preview
It should work now with:
npx nuxthub preview
@atinux This works great. But in the build output I see that the wrangler command is being shown for preview.
But the codebase shows npx nuxthub preview
, do I need to update something (I updated NuxtHub CLI
and @nuxthub/core
)?
Where do you see the wrangler command @ra-jeev ?
@atinux In the build output (pnpm build
). It should mention npx nuxthub preview
now, and I presume the code screenshot I pasted above should be doing that?
My bad, should be good with https://github.com/nuxt-hub/core/releases/tag/v0.7.19
Describe the bug Running nuxt build with cloudflare-pages preset, and
npx wrangler pages dev dist/
results inIntroduced somewhere after 0.7.9