Skip to content

next dev --turbo unable to import ESM-only packages when marked with serverComponentsExternalPackages #64525

@dstaley

Description

@dstaley

Link to the code that reproduces this issue

https://github.com/dstaley/next-turbo-external-esm

To Reproduce

  1. npm run dev:turbo
  2. Get error "The package seems invalid. require() resolves to a EcmaScript module, which would result in an error in Node.js."
  3. npm run dev
  4. Confirm that the page renders

Current vs. Expected behavior

Current behavior:

Package srcset (serverComponentsExtenalPackages or default list) can't be external
The request srcset matches serverComponentsExtenalPackages (or the default list), but it can't be external:
The package seems invalid. require() resolves to a EcmaScript module, which would result in an error in Node.js.

Expected behavior:
When running with next dev --turbo ESM-only packages that have been marked with serverComponentsExternalPackages should still be correctly imported.

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP Thu Jan 11 04:09:03 UTC 2024
  Available memory (MB): 32101
  Available CPU cores: 16
Binaries:
  Node: 18.19.0
  npm: 10.5.0
  Yarn: 1.22.22
  pnpm: 8.15.4
Relevant Packages:
  next: 14.2.1 // Latest available version is detected (14.2.1).
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.4.5
Next.js Config:
  output: N/A

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

Module resolution (CJS / ESM, module resolving), Turbopack (--turbo)

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

next dev (local)

Additional context

This reproduction uses the srcset package which is ESM-only.

PACK-2967

Metadata

Metadata

Assignees

No one assigned

    Labels

    Module ResolutionModule resolution (CJS / ESM, module resolving).TurbopackRelated to Turbopack with Next.js.bugIssue was opened via the bug report template.linear: turbopackConfirmed issue that is tracked by the Turbopack team.locked

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions