Skip to content

Fast refresh is broken by a lib using inline await #61452

@flo-dao

Description

@flo-dao

Link to the code that reproduces this issue

https://github.com/flo-dao/repro-fast-refresh

To Reproduce

  1. Start the app in dev
  2. Make a change in index.tsx
  3. You get a full page reload, with a message in the console indicating that fast refresh didn't work

Current vs. Expected behavior

Fast refresh should work

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.2.0: Wed Nov 15 21:54:51 PST 2023; root:xnu-10002.61.3~2/RELEASE_ARM64_T6030
Binaries:
  Node: 18.18.2
  npm: 9.8.1
  Yarn: 1.22.21
  pnpm: 8.14.0
Relevant Packages:
  next: 14.1.0
  eslint-config-next: 14.1.0
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.3.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Not sure, Module resolution (CJS / ESM, module resolving)

Which stage(s) are affected? (Select all that apply)

next dev (local)

Additional context

I pinpointed the code causing the issue in the bson lib, here is the link.

The final code looks like this in bson.mjs:

const nodejsRandomBytes = await (async () => {
    try {
        return (await import('crypto')).randomBytes;
    }
    catch {
        return nodejsMathRandomBytes;
    }
})();

If I turn this into a promise without async await, the fast refresh works as expected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Module ResolutionModule resolution (CJS / ESM, module resolving).bugIssue was opened via the bug report template.staleThe issue has not seen recent activity.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions