huozhi / bunchee

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

After update to v5, not working correctly #502

Closed suhaotian closed 8 months ago

suhaotian commented 8 months ago

Try update to v5 for xior,

first warning:

 ⚠️ Cannot export `import` field with .js or .cjs extension in CJS package, only .mjs extensions are allowed
│ ⚠️   ./dist/index.esm.js

Then solved by add type: module to package.json

Second:

only exports one entry, but I have many entries in exports:

image

exports:

{
 "exports": {
    "./plugins/error-retry": {
      "types": "./plugins/error-retry/index.d.ts",
      "require": "./plugins/error-retry/index.cjs",
      "import": "./plugins/error-retry/index.mjs",
      "module": "./plugins/error-retry/index.esm.js"
    },
    "./plugins/throttle": {
      "types": "./plugins/throttle/index.d.ts",
      "require": "./plugins/throttle/index.cjs",
      "import": "./plugins/throttle/index.mjs",
      "module": "./plugins/throttle/index.esm.js"
    },
    "./plugins/dedupe": {
      "types": "./plugins/dedupe/index.d.ts",
      "require": "./plugins/dedupe/index.cjs",
      "import": "./plugins/dedupe/index.mjs",
      "module": "./plugins/dedupe/index.esm.js"
    },
    "./plugins/cache": {
      "types": "./plugins/cache/index.d.ts",
      "require": "./plugins/cache/index.cjs",
      "import": "./plugins/cache/index.mjs",
      "module": "./plugins/cache/index.esm.js"
    },
    "./plugins/progress": {
      "types": "./plugins/progress/index.d.ts",
      "require": "./plugins/progress/index.cjs",
      "import": "./plugins/progress/index.mjs",
      "module": "./plugins/progress/index.esm.js"
    },
    "./plugins/mock": {
      "types": "./plugins/mock/index.d.ts",
      "require": "./plugins/mock/index.cjs",
      "import": "./plugins/mock/index.mjs",
      "module": "./plugins/mock/index.esm.js"
    },
    "./plugins/error-cache": {
      "types": "./plugins/error-cache/index.d.ts",
      "require": "./plugins/error-cache/index.cjs",
      "import": "./plugins/error-cache/index.mjs",
      "module": "./plugins/error-cache/index.esm.js"
    },
    ".": {
      "types": "./dist/types/index.d.ts",
      "require": "./dist/index.cjs",
      "import": "./dist/index.mjs",
      "module": "./dist/index.esm.js"
    }
  },
}
huozhi commented 8 months ago

I fixed it in 5.0.1! please upgrade to the new version 🙏

suhaotian commented 8 months ago

Thanks fix the issue, now it's working!

And found a small issue:

This will not generate ./dist/index.esm.js:

"exports": {
 ".": {
      "types": "./dist/index.d.ts",
      "require": "./dist/index.cjs",
      "import": "./dist/index.mjs",
      "module": "./dist/index.esm.js"
    },
}

So I change to:

"exports": {
 ".": {
      "types": "./dist/index.d.ts",
      "require": "./dist/index.cjs",
      "import": "./dist/index.mjs",
      "module": "./dist/index.mjs"
    },
}

and will generate dist/index.esm.js

huozhi commented 8 months ago

I’m confused, is module field generating .esm.js even when it’s specified as generating .mjs? Do you mind creating another issue and we can have repro and discussion there? Thanks!

suhaotian commented 8 months ago

Now it's working, after I did these change in package.json:

image