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]: Dev server with writeToDisk: true crashes if "asset/resource" is used for assets imported with query strings #8676

Closed
tmadeira opened this issue Dec 11, 2024 · 0 comments · Fixed by #8709
Labels
bug Something isn't working

Comments

@tmadeira
Copy link

System Info

  System:
    OS: macOS 14.4
    CPU: (11) arm64 Apple M3 Pro
    Memory: 95.98 MB / 18.00 GB
    Shell: 3.7.1 - /opt/homebrew/bin/fish
  Binaries:
    Node: 20.11.1 - ~/.asdf/installs/nodejs/20.11.1/bin/node
    Yarn: 1.22.22 - ~/.asdf/installs/nodejs/20.11.1/bin/yarn
    npm: 10.2.4 - ~/.asdf/plugins/nodejs/shims/npm
    pnpm: 9.12.3 - ~/.asdf/installs/nodejs/20.11.1/bin/pnpm
  Browsers:
    Chrome: 131.0.6778.139
    Safari: 17.4
  npmPackages:
    @rspack/cli: ^1.1.6 => 1.1.6
    @rspack/core: ^1.1.6 => 1.1.6
    @rspack/plugin-react-refresh: 1.0.0 => 1.0.0

Details

The dev server, more specifically webpack-dev-middleware, crashes with:

TypeError: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received undefined
    at Object.writeFile (node:fs:2295:5)
    at /.../rspack-project/node_modules/webpack-dev-middleware/dist/utils/setupWriteToDisk.js:54:21
    at FSReqCallback.oncomplete (node:fs:191:23) {
  code: 'ERR_INVALID_ARG_TYPE'
}
error Command failed with exit code 1.

when writeToDisk: true, some file is importing an asset using a query string in the end (e.g. ?v=2), and a rule "asset/resource" is used to load that asset.

Minimal change necessary to crash a project bootstraped using yarn create rspack: tmadeira/rspack-repro-writetodisk@8fce671

See the reproduce link and the reproduce steps for details.

Reproduce link

https://github.com/tmadeira/rspack-repro-writetodisk

Reproduce Steps

  1. Use yarn create rspack to create rspack project. I selected framework: React, language: TypeScript.
  2. Run yarn install. Note that yarn run dev works just fine.
  3. Now edit src/App.tsx to import ./App.css?v=2 instead of ./App.css, and edit rspack.config.ts to add a devServer.devMiddleware.writeToDisk: true and a module.rules[]: { test: /\.css$/, type: "asset/resource" }. The changes should look like this: tmadeira/rspack-repro-writetodisk@8fce671
  4. Run yarn run dev again. This time it will fail with:
TypeError: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received undefined
    at Object.writeFile (node:fs:2295:5)
    at /.../rspack-project/node_modules/webpack-dev-middleware/dist/utils/setupWriteToDisk.js:54:21
    at FSReqCallback.oncomplete (node:fs:191:23) {
  code: 'ERR_INVALID_ARG_TYPE'
}
error Command failed with exit code 1.
@tmadeira tmadeira added bug Something isn't working pending triage The issue/PR is currently untouched. labels Dec 11, 2024
@inottn inottn removed the pending triage The issue/PR is currently untouched. label Dec 13, 2024
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

Successfully merging a pull request may close this issue.

2 participants