web-infra-dev / rslib

The Rsbuild powered package build tool.
https://lib.rsbuild.dev/
MIT License
383 stars 19 forks source link

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

Open tym3515 opened 1 week ago

tym3515 commented 1 week ago

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" }

Timeless0911 commented 1 week ago

Can you describe clearly and provide a reproduce demo?

fi3ework commented 1 week ago

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