Skip to content

Could not resolve "async_hooks" #116

Open
@buhodev

Description

@buhodev

Even tho the sveltekit package is importing AsyncLocalStorage from node:asyn_hooks:

import { AsyncLocalStorage } from 'node:async_hooks';

the tracing.ts file is not prepending node:,

import { AsyncLocalStorage } from 'async_hooks';

which is causing an error on build on cloudflare:

15:38:03.971	✘ [ERROR] Build failed with 1 error:
15:38:03.972	
15:38:03.972	  ✘ [ERROR] Could not resolve "async_hooks"
15:38:03.972	  
15:38:03.972	      ../output/server/chunks/flags.js:1:118:
15:38:03.972	        1 │ ...syncLocalStorage as q}from"async_hooks";import{AsyncLocalStorage...
15:38:03.973	          ╵                              ~~~~~~~~~~~~~
15:38:03.973	  
15:38:03.973	    The package "async_hooks" wasn't found on the file system but is built into node.

I already followed the suggestions (adding nodejs_compat and the latest compatibility_date) with no luck. What works is patching the flag package with bun patch, but I need to do it on every update of the flags package (which is not a burden tbh but still would prefer not to do it manually everytime)

Activity

linked a pull request that will close this issue on Apr 8, 2025
dferber90

dferber90 commented on Apr 10, 2025

@dferber90
Collaborator

We had #51 open before, where I published a snapshot release using node:async_hooks in this comment. Can you see if the snapshot release would fix it for you?

Can you try @vercel/flags@3.1.1-475dd26e-20250206133544 and let me know whether that works for you? The release is slightly outdated now but might be good enough to see if node:async_hooks would actually work for you

buhodev

buhodev commented on Apr 23, 2025

@buhodev
Author

I can confirm that using @vercel/flags@3.1.1-475dd26e-20250206133544 works. The build was successful cc @dferber90

KBeDevel

KBeDevel commented on May 16, 2025

@KBeDevel

Same issue using flags@4.0.0 and flags@4.0.1-ff75a409-20250506071241

dferber90

dferber90 commented on May 18, 2025

@dferber90
Collaborator

For anyone running into the async_hooks issue, can you leave more details on this issue?

  • Are you using flags/next or flags/sveltekit
  • If using flags/next, are you sure you are not using flags in client components?

If possible, please share a minimal reproduction.

alehar9320

alehar9320 commented on May 24, 2025

@alehar9320

Receiving this error too. NextJS App Router.

deps:

  • "react": "19.0.0",
  • "next": "~15.2.4",
  • "flags": "^4.0.1",

flags.tsx
`
import { flag } from 'flags/next';

export const themableFlag = flag({
key: 'themable-flag',
decide: () => false,
});
`

mycomponent.tsx
`
import { themableFlag } from '@/app/feature-flags/flags';
import ApplicationTopBarClient from './ApplicationTopBarClient';

export default async function ApplicationTopBar() {
const isThemable = await themableFlag();
return ;
}`

Hope this helps debug.

edit: for anyone else experiencing this error - ensure that you put the call to flags inside a page.tsx or layout.tsx file, rather than a sub-component. Then pass on the value as input to the following components.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @dferber90@alehar9320@KBeDevel@buhodev

      Issue actions

        Could not resolve "async_hooks" · Issue #116 · vercel/flags