Skip to content

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

@Alfred-Mountfield

Description

@Alfred-Mountfield

Verify canary release

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

Provide environment information

❯ next info

Operating System:
  Platform: linux
  Arch: x64
  Version: Ubuntu 20.04.0 LTS Sun Dec 04 2022 17:02:37 GMT+0000 (Greenwich Mean Time)
Binaries:
  Node: 16.14.2
  npm: 7.17.0
  Yarn: 1.22.19
  pnpm: 7.13.6
Relevant packages:
  next: 13.0.7-canary.1
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0

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

No response

Link to reproduction - Issues with a link to complete (but minimal) reproduction code will be addressed faster

https://stackblitz.com/edit/vercel-next-js-r1qnjk?file=next-app/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
  • Run next dev and see it succeeds
  • Run next build and see it fail

Describe the Bug

From my testing, next build doesn't seem to support importing from package's conditional imports. Weirdly next dev runs successfully, but when you run next dev you get errors about how the package can't be found:

$ next build
info  - Linting and checking validity of types ...Failed to compile.

./pages/index.tsx:5:21
Type error: Cannot find module 'demo-package/alt' or its corresponding type declarations.

  3 | 
  4 | /** Works in next dev, breaks in next build */
> 5 | import { foo } from 'demo-package/alt';

Expected Behavior

I would expect next build to be able to resolve the entrypoint like next dev does.

Which browser are you using? (if relevant)

Chrome 107.0.5304.110

How are you deploying your application? (if relevant)

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssue was opened via the bug report template.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions