rslib icon indicating copy to clipboard operation
rslib copied to clipboard

[Bug]: Multiple entry files packaged esm file import error undefind

Open tym3515 opened this issue 1 year ago • 2 comments

Version

"@rslib/core": "^0.0.12",

{ format: 'esm', output: { injectStyles: true, asyncChunks:false, distPath: { root: './dist/esm', css: '.', cssAsync: '.', }, },

Details

entry: { install: './src/install.js', Active: './src/lib/Active.js', }

Reproduce link

aAAA

Reproduce Steps

"devDependencies": { "@eslint/js": "^9.12.0", "@rsbuild/core": "^1.0.13", "@rsbuild/plugin-basic-ssl": "^1.1.1", "@rsbuild/plugin-sass": "^1.0.3", "@rsbuild/plugin-vue2": "^1.0.1", "@rslib/core": "^0.0.12", "eslint": "^9.12.0", "globals": "^15.11.0", "prettier": "^3.3.3" }

tym3515 avatar Oct 22 '24 04:10 tym3515

Can you describe clearly and provide a reproduce demo?

Timeless0911 avatar Oct 22 '24 04:10 Timeless0911

A minimal reproduction with webpack. https://stackblitz.com/edit/node-oapeg8?file=webpack.config.js,package.json,bar.js,dist-single-entry%2Fmain.mjs,README.md

Currently, the main issue is that when there are multiple entries, the bailout reasons between different entries are not isolated. This affects the concatenation results of each entry.

With multiple entries, the ./bar.js bails out from main concatenation module. There is no problem when only a main entry.

asset main.mjs 2.98 KiB [emitted] [javascript module] (name: main)
asset bar.mjs 1.65 KiB [compared for emit] [javascript module] (name: bar)
Entrypoint main 2.98 KiB = main.mjs
Entrypoint bar 1.65 KiB = bar.mjs
runtime modules 1.31 KiB 6 modules
orphan modules 61 bytes [orphan] 1 module
cacheable modules 209 bytes
  ./main.js + 1 modules 183 bytes [built] [code generated]
+    ModuleConcatenation bailout: Cannot concat with ./bar.js: Module is an entry point
  ./bar.js 26 bytes [built] [code generated]
webpack 5.95.0 compiled successfully in 124 ms

fi3ework avatar Oct 22 '24 08:10 fi3ework

https://github.com/web-infra-dev/rslib/pull/1273

Advanced ESM will output like

// 451.js
const bar = ()=>'bar';
export { bar };

// bar.js
const bar = ()=>'bar';
export { bar };

// foo.js
import { bar } from "./451.js";
const foo = 'foo' + bar;
export { foo };

// index.js
import { bar } from "./451.js";
const foo = 'foo' + bar;
const src_text = ()=>`hello / foo: ${foo} / bar: ${bar}`;
export { src_text as text };

Still need to optimize the output when bar is also an entry.

Timeless0911 avatar Oct 30 '25 09:10 Timeless0911

Resolved with advancedEsm enabled.

Timeless0911 avatar Nov 19 '25 09:11 Timeless0911