Skip to content

next build fails on importing a packaging via its conditional export #45452

Closed as not planned
@marcoreni

Description

@marcoreni

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 22.3.0: Thu Jan  5 20:48:54 PST 2023; root:xnu-8792.81.2~2/RELEASE_ARM64_T6000
Binaries:
  Node: 18.12.0
  npm: 8.19.2
  Yarn: 1.22.19
  pnpm: 7.26.1
Relevant packages:
  next: 13.1.7-canary.0
  eslint-config-next: 13.1.5
  react: 18.2.0
  react-dom: 18.2.0

Which area(s) of Next.js are affected? (leave empty if unsure)

TypeScript

Link to the code that reproduces this issue

https://stackblitz.com/edit/vercel-next-js-fkhtk7?file=pages/index.tsx

To Reproduce

  • Add a dependency on a package which has a conditional export entrypoint.
  • Try and import via its conditional entrypoint path, while using "moduleResolution: node16"
  • Run next dev and see it succeeds
  • Run tsc --noEmit and see it succeeds
  • Run next build and see it fails with Type error: Cannot find module '...' or its corresponding type declarations.

Describe the Bug

This is probably a perfect clone of #43698 , however I think the issue is NOT on Typescript side.

The main difference with the other issue is that running tsc --noEmit works perfectly, while using moduleResolution: node16. It (correctly) fails while using moduleResolution: node, since exports only work with node16/nodenext. next build, however, always fails.

I saw #44177 merged in the latest canary, but while dev works perfectly (and I'm able to use the components), build compiles correctly but fails in type checking. Maybe something else is missing?

Expected Behavior

The build should work

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    TypeScriptRelated to types with Next.js.bugIssue was opened via the bug report template.lockedstaleThe 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