huozhi / bunchee

Zero config bundler for ECMAScript and TypeScript packages
https://npmjs.com/bunchee
858 stars 28 forks source link

The `src` folder was deleted when exporting a TypeScript file in the "development" field. #555

Closed thecuvii closed 4 days ago

thecuvii commented 1 week ago

When exporting a TypeScript file with the development field, such as src/index.ts, there will be an Error [RollupError]: Could not resolve entry module "src/index.ts". error, and the src folder was deleted.

  "exports":{
    "development":"./src/index.ts",
    "default":"./dist/index.mjs"
  },

https://github.com/huozhi/bunchee/assets/11806619/f1ad3eb9-d402-475d-95d2-289a9da8c910

repro: https://github.com/thecuvii/bunchee-development-repro

huozhi commented 1 week ago

It sounds wrong to export ts file in exports field, especially they're also the source file. If you're doing that and rely on the consumer side (which is the framework bundler or any app using a framework), you don't need bundling anymore since they're source files themselves. But in general it's a weird practice.

We could probably error with sth else but it's still going to be errored

thecuvii commented 1 week ago

I use this pattern in a monorepo, so I don't have to run a dev command for each package. The main issue here is that the "src" folder should not be deleted, as I may lose all my uncommitted source files.

huozhi commented 1 week ago

Yea that's right, the src/ folder or source files shouldn't be auto deleted. I can fix that later. But why it's using bunchee if this package doesn't need to use bunchee? IMO it's weird to determine what to do if your input path is same as output or if your output is ts file

thecuvii commented 1 week ago

LOL, I use bunchee, just trying to figure out if it's possible to export a TypeScript file for development only, and then encounter this problem.

huozhi commented 1 week ago

yea should def keep the files there