web-infra-dev / rspack

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

[Bug]: libraryTarget is umd , third party packs with "amd" not being converted #6293

Open zaohuayudie opened 6 months ago

zaohuayudie commented 6 months ago

System Info

System: OS: macOS 14.3.1 CPU: (12) arm64 Apple M2 Pro Memory: 434.50 MB / 32.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 18.17.1 - ~/.nvm/versions/node/v18.17.1/bin/node Yarn: 1.22.22 - ~/xxx/node_modules/.bin/yarn npm: 9.6.7 - ~/.nvm/versions/node/v18.17.1/bin/npm pnpm: 8.15.6 - ~/Library/pnpm/pnpm Browsers: Chrome: 123.0.6312.124 Safari: 17.3.1

Details

output: {
    path: `${__dirname}/dist`,
    filename: '[name].[hash].js',
    umdNamedDefine: true,
    libraryTarget: 'umd',
    library: {
      name: `@xxxxx-[name]`,
      type: 'umd',
      umdNamedDefine: true,
    },
  },

1.dist contains a large number of amd definitions, resulting in an error when executing js

  1. The third-party package is exported in esm mode but not compiled. How do I convert the esm to cjs

Reproduce link

No response

Reproduce Steps

  1. rspack build 2.use dist in browser 3.show error image
zaohuayudie commented 6 months ago

System Info

System: OS: macOS 14.3.1 CPU: (12) arm64 Apple M2 Pro Memory: 434.50 MB / 32.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 18.17.1 - ~/.nvm/versions/node/v18.17.1/bin/node Yarn: 1.22.22 - ~/xxx/node_modules/.bin/yarn npm: 9.6.7 - ~/.nvm/versions/node/v18.17.1/bin/npm pnpm: 8.15.6 - ~/Library/pnpm/pnpm Browsers: Chrome: 123.0.6312.124 Safari: 17.3.1

Details

output: {
    path: `${__dirname}/dist`,
    filename: '[name].[hash].js',
    umdNamedDefine: true,
    libraryTarget: 'umd',
    library: {
      name: `@xxxxx-[name]`,
      type: 'umd',
      umdNamedDefine: true,
    },
  },

1.dist contains a large number of amd definitions, resulting in an error when executing js 2. The third-party package is exported in esm mode but not compiled. How do I convert the esm to cjs

Reproduce link

No response

Reproduce Steps

  1. rspack build 2.use dist in browser 3.show error
image

loader amd error message:

image

Uncaught Error: Can only have one anonymous define call per script file

I found the reason: it was umd packaging, the packaging merge for amd, did not remove duplicate amd definitions, which should have been a bug, amd only ran the definition once when loading. Hope to repair as soon as possible, urgent!!

This time the switch from webpack to rspack has seen significant improvements in concurrent builds, but hopefully we can respond quickly to fix this issue in time.

github-actions[bot] commented 6 months ago

Hello @zaohuayudie, sorry we can't investigate the problem further without reproduction demo, please provide a repro demo by forking rspack-repro, or provide a minimal GitHub repository by yourself. Issues labeled by need reproduction will be closed if no activities in 14 days.

zaohuayudie commented 6 months ago

Hello @zaohuayudie, sorry we can't investigate the problem further without reproduction demo, please provide a repro demo by forking rspack-repro, or provide a minimal GitHub repository by yourself. Issues labeled by need reproduction will be closed if no activities in 14 days.

thanks very much! The final cause was found, which was a bug caused by the monaco editor loader loading amd. But why is webpack packaging OK, rspack packaging has.

You can close the question now.

github-actions[bot] commented 6 months ago

Since the issue was labeled with need reproduction, but no response in 14 days. This issue will be closed. Feel free to comment and reopen it if you have any further questions.

LaamGinghong commented 3 months ago

with the same issue

fi3ework commented 3 months ago

reproduction: https://github.com/fi3ework-reproduction/rspack-6293

stale[bot] commented 1 month 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!