vercel / next.js

The React Framework
https://nextjs.org
MIT License
127.34k stars 27.02k forks source link

Unexpected behavior when doing `export *` (cyclic imports) #22283

Open JuanM04 opened 3 years ago

JuanM04 commented 3 years ago

What version of Next.js are you using?

10.0.8-canary.1

What version of Node.js are you using?

12, 15

What browser are you using?

All

What operating system are you using?

Linux

How are you deploying your application?

local

Describe the Bug

(Original issue: https://github.com/blitz-js/legacy-framework/issues/408)

I'm having some problems when importing. I have this validation folder with zod utilites:

validation
├── cuit.js
├── index.js
├── ncm.js
└── others.js

Inside index.js, I have this:

export * from "./cuit"
export * from "./ncm"
export * from "./others"

When I import from validation, it throws undefined. If I change each import to its respective file (instead of a big import { ... } from 'validation', I do import { .. } from 'validation/cuit' or import { .. } from 'validation/ncm'), it works.

What's weird is what happens when I rearrange the imports like this:

export * from "./others"
export * from "./cuit"
export * from "./ncm"

If I put others at the top, it just works.

Expected Behavior

It should work no matter the export order.

To Reproduce

https://codesandbox.io/s/nextjs-exports-bug-pbri4

u3u commented 2 years ago

The same problem occurs with v12.2.0 and this only happens with server-side rendering. Strangely enough only individual exports have this problem.

jankaifer commented 1 year ago

I checked your repro and it seems that cuit and ncm both have import {...} from '.'. Cyclic imports are really wonky and shouldn't be used (if possible).