web-infra-dev / rspack

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

[Bug]: Error using html-bundler-webpack-plugin #5971

Closed webdiscus closed 2 months ago

webdiscus commented 6 months ago

System Info

System: OS: macOS 14.4 CPU: (10) arm64 Apple M1 Max Memory: 790.63 MB / 64.00 GB Binaries: Node: 18.18.2 npm: 9.8.1

Details

RSPack and HTML Bundler

A symbiosis of the fast RSPack and the powerful html-bundler-webpack-plugin could be a Vite killer. This plugin is an advanced successor to html-webpack-plugin.

But currently RSPack v0.5.8 is yet not 100% compatible with the Webpack.

Using the html-bundler-webpack-plugin with RSPack occurs the issue:

/Users/xxxx/html-bundler-webpack-plugin/experiments/rspack/node_modules/@rspack/core/dist/Compiler.js:518
    __classPrivateFieldSet(this, _Compiler_instance, new instanceBinding.Rspack(rawOptions, this.builtinPlugins, {
                                                     ^

Error: Failed to convert JavaScript value `function filenameFn(..) ` into rust type `String`

    at Compiler._Compiler_getInstance (/Users/xxxx/html-bundler-webpack-plugin/experiments/rspack/node_modules/@rspack/core/dist/Compiler.js:518:54)
    at Compiler.build (/Users/xxxx/html-bundler-webpack-plugin/experiments/rspack/node_modules/@rspack/core/dist/Compiler.js:384:87)
    at /Users/xxxx/html-bundler-webpack-plugin/experiments/rspack/node_modules/@rspack/core/dist/Watching.js:263:23
    at Hook.eval [as callAsync] (eval at create (/Users/xxxx/html-bundler-webpack-plugin/experiments/rspack/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:24:1)
    at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/Users/xxxx/html-bundler-webpack-plugin/experiments/rspack/node_modules/tapable/lib/Hook.js:18:14)
    at Watching._Watching_go (/Users/xxxx/html-bundler-webpack-plugin/experiments/rspack/node_modules/@rspack/core/dist/Watching.js:253:34)
    at Watching._Watching_invalidate (/Users/xxxx/html-bundler-webpack-plugin/experiments/rspack/node_modules/@rspack/core/dist/Watching.js:217:74)
    at /Users/xxxx/html-bundler-webpack-plugin/experiments/rspack/node_modules/@rspack/core/dist/Watching.js:51:94
    at process.processTicksAndRejections (node:internal/process/task_queues:77:11) {
  code: 'GenericFailure'
}

The filename property of an entry object can be string or function (pathData, assetInfo) => string. See please the Webpack documentation for the filename.

There is very simple rspack.config.js:

const path = require('path');
const HtmlBundlerPlugin = require('html-bundler-webpack-plugin');

module.exports = {
  output: {
    path: path.join(__dirname, 'dist/'),
    publicPath: '',
  },

  entry: {},

  plugins: [
    new HtmlBundlerPlugin({
      entry: {
        index: './src/template.html',
      },
    }),
  ],
};

Note

The HTML Bundler Plugin works fine with Webpack and has over 96% test coverage.

P.S. The reference to original issue is RSPack support and compatibility

Reproduce link

https://github.com/webdiscus/html-bundler-webpack-plugin/tree/master/experiments/rspack

Reproduce Steps

clone https://github.com/webdiscus/html-bundler-webpack-plugin.git
cd html-bundler-webpack-plugin/experiments/rspack
npm i
npm run dev
stale[bot] commented 4 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!