bunchee icon indicating copy to clipboard operation
bunchee copied to clipboard

Shared modules should inherit file extension (e.g. `.mjs`)

Open amannn opened this issue 1 year ago • 2 comments

Another week, another bug report :).

I noticed when you have a build that generates .mjs files (since the package uses type: 'commonjs'), then shared modules of the entry points will use the .js extension. This results in consumer errors if the shared module has further imports since all modules that use ESM in this graph should use the .mjs extension.

Reproduction: ./dist/esm/core.mjs

In the linked example this works, but if utils-shared-BdVwpBM3.js would have another import (e.g. import Link from 'next/link') then this would break:

Module parse failed: 'import' and 'export' may appear only with 'sourceType: module' (1:0)

amannn avatar Jun 26 '24 12:06 amannn

Hmm, same seems to be true also for separate chunks that are created via the 'use client' split: react.mjs.

amannn avatar Jun 26 '24 15:06 amannn

I changed the feature to experimental, probably still need to use a separate entry to achieve it for now 😢 The spit chunks feature is quite limited for do this automatically with rollup. I'm still exploring the other ways to do it

huozhi avatar Jun 29 '24 10:06 huozhi