Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Invalid code generated when dll reference manifest contains moduleArgument: webpackModule, #9094

Open
robrichard opened this issue Jan 22, 2025 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@robrichard
Copy link

System Info

  System:
    OS: macOS 15.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 103.56 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.11.1 - /usr/local/bin/node
    Yarn: 1.22.19 - ~/.npm-global/bin/yarn
    npm: 10.2.4 - /usr/local/bin/npm
    pnpm: 9.1.1 - /usr/local/bin/pnpm
    bun: 1.0.0 - ~/.bun/bin/bun
    Watchman: 2023.09.04.00 - /opt/homebrew/bin/watchman
  Browsers:
    Chrome: 131.0.6778.265
    Safari: 18.1
  npmPackages:
    @rspack/cli: ^1.2.0 => 1.2.0 
    @rspack/core: ^1.2.0 => 1.2.0 

Details

Bundle a dll containing a module that adds to the manifest buildMeta.moduleArgument: "webpackModule".

When a bundle is created that references that module the generated code looks like:

"960": (function (__webpack_module__, __unused_webpack___webpack_exports__, __webpack_require__) {
module.exports = __webpack_require__(/*! dll-reference my_dll */ 94)(6019);

}),

The first argument of the generated function is __webpack_module__, but the body of the code references module.exports =. This causes a runtime error:

main.js:12 Uncaught ReferenceError: module is not defined
    at 960 (main.js:12:1)
    at __webpack_require__ (main.js:39:30)
    at main.js:111:87
    at main.js:120:3
    at main.js:122:3

Reproduce link

https://github.com/robrichard/rspack-dll-test/tree/webpack-module

Reproduce Steps

See the webpack-module branch of the above linked repo

Build with dll and dll reference plugin: npm run build

$ npm run build                                                       

> [email protected] build
> rspack build -c ./config/rspack.dll.config.js && rspack build -c ./config/rspack.dllRef.config.js

Rspack compiled successfully in 67 ms
Rspack compiled successfully in 12 ms

Open public/index.html in a browser and see in the console:

main.js:12 Uncaught ReferenceError: module is not defined
    at 960 (main.js:12:1)
    at __webpack_require__ (main.js:39:30)
    at main.js:111:87
    at main.js:120:3
    at main.js:122:3

Generated code:

(() => { // webpackBootstrap
var __webpack_modules__ = ({
"622": (function (module, __unused_webpack___webpack_exports__, __webpack_require__) {
module.exports = __webpack_require__(/*! dll-reference my_dll */ 94)(1847);

}),
"334": (function (module, __unused_webpack_exports, __webpack_require__) {
module.exports = __webpack_require__(/*! dll-reference my_dll */ 94)(4311);

}),
"960": (function (__webpack_module__, __unused_webpack___webpack_exports__, __webpack_require__) {
module.exports = __webpack_require__(/*! dll-reference my_dll */ 94)(6019);

}),
"94": (function (module) {
"use strict";
module.exports = my_dll;

}),

});

Note in "960", module.exports is referenced, while the module arg is __webpack_module__

@robrichard robrichard added bug Something isn't working pending triage The issue/PR is currently untouched. labels Jan 22, 2025
@chenjiahan chenjiahan removed the pending triage The issue/PR is currently untouched. label Jan 26, 2025
@inottn
Copy link
Collaborator

inottn commented Feb 7, 2025

@ahabhgk Hello, I have a question. In webpack, module_argument and exports_argument are defined in BuildInfo, but in Rspack, they are defined in BuildMeta. This issue might be related to this. I'd like to know if this behavior is a bug or intentional.

@ahabhgk
Copy link
Contributor

ahabhgk commented Feb 7, 2025

I'm not sure, I think @LingyuCoder has more information about that

@LingyuCoder
Copy link
Contributor

I'm not quite sure either. It seems that placing module_argument and export_argument on build_meta was caused by the misalignment of the early code of Rspack. Moving it should be fine. But placing it on build_meta or build_info doesn't affect the final result.

This issue seems to be that external and dll, and module_argument is not used while generating the code of the external module.

@inottn
Copy link
Collaborator

inottn commented Feb 7, 2025

I'm not quite sure either. It seems that placing module_argument and export_argument on build_meta was caused by the misalignment of the early code of Rspack. Moving it should be fine. But placing it on build_meta or build_info doesn't affect the final result.

This issue seems to be that external and dll, and module_argument is not used while generating the code of the external module.

Okay, I can try to align with webpack's behavior first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants