Skip to content

Binary file corruption: unplugin treats binary files as text #524

@Loccko

Description

@Loccko

Environment

  • platform: all
  • unplugin version: 1.16.1
  • nodejs: 20.19.2
  • package manager: [email protected]

Reproduction

Repo: https://github.com/Loccko/unplugin-webpack-issues/tree/main
To reproduce:

  1. Clone
  2. npm ci
  3. npm run build:webpack
  4. Try to open images/font from dist folder

Describe the bug

When using @intlify/unplugin-vue-i18n, unplugin corrupts all binary files (e.g., .jpg, .png, .svg) in the project, which then cannot be used in Vue components.

The root cause is unplugin/dist/webpack/loaders/load.js, which during execution calls the loader from @intlify/unplugin-vue-i18n. This loader does nothing with the source of these files (since the loader's condition check doesn't match). Subsequently, unplugin/dist/webpack/loaders/load checks the result of the unplugin-vue-i18n loader execution, which is undefined, and unplugin/dist/webpack/loaders/load calls the callback with the original input source.

Debug Screenshot 3

Original code: https://github.com/unjs/unplugin/blob/v1.16.1/src/webpack/loaders/load.ts

Since unplugin/dist/webpack/loaders/load.js lacks the raw = true variable, webpack treats the source as regular text content and attempts to process it as text rather than binary data.
Info: https://webpack.js.org/api/loaders/#raw-loader

This results in corruption of all binary files, leading to broken image and font files that cannot be used.

Note: This issue appears to be relevant for both [email protected] and [email protected], as both major versions lack this variable.

Additional context

No response

Logs

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions