Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wrangler dev] Can't resolve node:async_hooks #273

Open
remihuigen opened this issue Sep 11, 2024 · 9 comments
Open

[wrangler dev] Can't resolve node:async_hooks #273

remihuigen opened this issue Sep 11, 2024 · 9 comments

Comments

@remihuigen
Copy link

Describe the bug
Running nuxt build with cloudflare-pages preset, and npx wrangler pages dev dist/ results in

✘ [ERROR] service core:user:worker: Uncaught Error: No such module "node:async_hooks".

    imported from "r4j10pyoufr.js"


✘ [ERROR] MiniflareCoreError [ERR_RUNTIME_FAILURE]: The Workers runtime failed to start. There is likely additional logging output above.

Introduced somewhere after 0.7.9

@adamkasper
Copy link

adamkasper commented Sep 11, 2024

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 },
})

@atinux atinux changed the title Can't resolve node:async_hooks [wrangler dev] Can't resolve node:async_hooks Sep 11, 2024
@atinux
Copy link
Contributor

atinux commented Sep 11, 2024

@adamkasper this is not related to the main issue, see #261 (comment) (should be fixed in upcoming Nuxt release)

@atinux
Copy link
Contributor

atinux commented Sep 11, 2024

Let me have a look @remihuigen

@atinux
Copy link
Contributor

atinux commented Sep 11, 2024

Why do you need to run the npx wrangler pages dev dist/ command @remihuigen ?

@remihuigen
Copy link
Author

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

@remihuigen
Copy link
Author

To confirm: I'm not getting the error in production

@atinux
Copy link
Contributor

atinux commented Sep 11, 2024

I see, well the debugging is not perfect yes as I don't provide the wrangler.toml, let me track this on nuxt-hub/cli#22

@remihuigen
Copy link
Author

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

@ra-jeev
Copy link
Contributor

ra-jeev commented Sep 14, 2024

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.

Note: This issue started with v0.7.12 (Async Local Storage release)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants