module-builder icon indicating copy to clipboard operation
module-builder copied to clipboard

Type generation is broken for subfolders (subfolder is imported with .js extension)

Open madskronborg opened this issue 1 year ago • 2 comments

Reproduction

Stackblitz

Build command: cd ~/projects/vitejs-vite-tu4fsx/my-module/ && npm run dev:build && npm run prepack

Describe the bug

After upgrading from 0.5.5 to 0.8.0 the generated bundle has invalid import paths for types that exist in subfolders.

We have e.g. the following structure in our nuxt module runtime/ folder:

src/
  runtime/
    types/
      index.ts (export * from './components')
      components/
        index.ts (export * from './Alert')
        Alert.ts

Which results in the following build:

dist/
  runtime/
    types/
      index.d.ts (export * from './components.js')
      components/
        index.d.ts (export * from './Alert.js')
        Alert.d.ts
        Alert.js

Where the path ./components.js is invalid. It should be: ./components. I am also unsure whether components/index.d.ts in the build should export ./Alert.js or Alert.d.ts.

madskronborg avatar Jul 03 '24 09:07 madskronborg

I'll fix this, but you should probably do from './components/index' anyway. (And this should probably resolve the issue for now.)

danielroe avatar Jul 03 '24 17:07 danielroe

I'll fix this, but you should probably do from './components/index' anyway. (And this should probably resolve the issue for now.)

Thank you for the quick reply and the great work on nuxt! :)

I hadn't thought about referencing the index file directly - I tested it and it does indeed fix the type referencing.

Appreciate the help :+1:

madskronborg avatar Jul 04 '24 06:07 madskronborg

I think fixing this issue or at least logging some warnings when importing from a folder index (without filename) will probably save us a lot of time debugging type issues in the future 😅

Not sure where to start to work on a fix 😥

BobbieGoede avatar Sep 10 '24 14:09 BobbieGoede

Was just looking at this. I think maybe issue is upstream in mkdist.

danielroe avatar Sep 10 '24 14:09 danielroe