web-infra-dev / rspack

The fast Rust-based web bundler with webpack-compatible API 🦀️
https://rspack.dev
MIT License
8.52k stars 501 forks source link

Build Result is different when configure optimization and umd #3958

Open TopGrd opened 1 year ago

TopGrd commented 1 year ago

System Info

System Info System: OS: macOS 13.4.1 CPU: (8) x64 Apple M1 Memory: 33.23 MB / 16.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 16.20.0 - ~/git/nvs/default/bin/node Yarn: 1.22.19 - ~/.npm-global/bin/yarn npm: 8.10.0 - ~/.npm-global/bin/npm pnpm: 7.26.3 - ~/Library/pnpm/pnpm Browsers: Chrome: 115.0.5790.170 Chrome Canary: 118.0.5939.0 Safari: 16.5.1 npmPackages: @rspack/cli: latest => 0.2.11 @rspack/plugin-minify: ^0.1.12 => 0.1.12 @rspack/plugin-node-polyfill: latest => 0.1.12

Details

Build error when building with library and optimization config at the same time. Uncaught ReferenceError: require is not defined

But when I remove the optimization configuration, every thing is ok.

When configuring the optimization, M and P are assigned the value of an object, so the subsequent require logic is executed. image

image

When i remove the optimization config, module and exports is undefined, so the bottom logic is executed image

Reproduce link

https://github.com/TopGrd/rspack-umd-bug

Reproduce Steps

npm i npm run build serve ./dist

stale[bot] commented 8 months ago

This issue has been automatically marked as stale because it has not had recent activity. If this issue is still affecting you, please leave any comment (for example, "bump"). We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!

hardfist commented 1 month ago

@TopGrd can you help checkout whether this problem still exists using latest version