`?raw` imports work in `vp dev` but fail in `vp pack`, from the same `vite.config.ts`
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 65/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- node.js, typescript, vite
- Lĩnh vực
- build-system, tooling
Hướng nghiên cứu
Look at how vite-plus handles asset queries in pack mode, starting from the pack command's build pipeline. The issue mentions that rolldown's load hook receives the path with ?raw attached, but the default file reader fails. Examine the pack configuration and loader logic in vite-plus's source, likely around src/pack or src/plugins. The fix should ensure ?raw imports are processed similarly to ?inline. Test with the provided reproduction to verify the fix works for both dev and pack.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Describe the bug
Disclaimer: I formatted this with an LLM.
My library inlines an HTML template and some SVG icons as strings with ?raw:
import svg from "./x.svg?raw";
vp dev serves the file contents, as plain Vite does. vp pack stops with
UNLOADABLE_DEPENDENCY, because it tries to open a file literally named
x.svg?raw. An ?inline CSS import in the same file packs fine, so pack
handles some asset queries and not others, and the
pack guide does not say which.
I am filing this here rather than with tsdown because what breaks is the Vite+
promise that one config means the same thing to vp dev and vp pack. Nothing
in the config warns that the two commands read this import differently.
The gap looks small. Rolldown already resolves the import: a plugin's load
hook receives the absolute path with ?raw still attached. Only the default
file reader fails. This plugin in pack.plugins fixes it:
import { readFileSync } from "node:fs";
import type { Plugin } from "vite-plus";
function rawImports(): Plugin {
const RAW = /\?raw$/;
return {
name: "raw-imports",
load: {
filter: { id: RAW },
handler: (id) =>
`export default ${JSON.stringify(readFileSync(id.replace(RAW, ""), "utf-8"))};`,
},
};
}
pack: { loader: { ".svg": "text" } } does not fix it. It matches on file
extension, so the source has to drop ?raw, and then vp dev returns a URL for
the import instead of the contents. That swaps a build error for a silent
difference between dev and the published build.
What I would like:
vp packhandles the asset queriesvp devhandles,?rawat least.- Failing that, the pack guide lists the queries pack supports, and the error
names the query and points atloaderor a plugin.
A related question: tsdown's guide says it "is positioned to become the
foundation for Rolldown Vite's Library Mode". Should library authors on
vp pack expect Vite's asset queries to arrive there eventually, or plan on
keeping their own plugins for them? Either answer is fine to build against. The
closest existing thread is tsdown discussion
#631.
Reproduction
No URL, follow reproduction steps below.
Steps to reproduce
Create the project:
mkdir vp-raw-repro && cd vp-raw-repro && mkdir src
cat > package.json <<'EOF'
{
"name": "vp-raw-repro",
"private": true,
"type": "module",
"devDependencies": { "vite-plus": "1.0.0-rc.0" }
}
EOF
cat > vite.config.ts <<'EOF'
import { defineConfig } from "vite-plus";
export default defineConfig({
pack: { entry: "src/index.ts" },
});
EOF
cat > src/index.ts <<'EOF'
import svg from "./x.svg?raw";
import css from "./y.css?inline";
export { svg, css };
EOF
echo '<svg xmlns="http://www.w3.org/2000/svg"/>' > src/x.svg
echo 'p { color: red; }' > src/y.css
npm install
-
Run
npx vp dev. In a second terminal, fetch the URL the dev server rewrites
the import to:curl -s 'http://localhost:5173/src/x.svg?import&raw'It prints
export default "<svg xmlns=\"http://www.w3.org/2000/svg\"/>\n". -
Stop the dev server and run
npx vp pack. It fails with
UNLOADABLE_DEPENDENCY(log below). -
Remove the
?rawimport and pack again:printf 'import css from "./y.css?inline";\n\nexport { css };\n' > src/index.ts npx vp packIt builds, and
dist/index.mjsholds the CSS as a string.
System Info
$ vp env current
Node.js:
Version 24.11.0
Source system PATH
Bin Path /home/myuser/.local/share/zed/node/node-v24.11.0-linux-x64/bin/node
Installed true
Mode system_first
Package Manager:
Name npm
Version 11.6.1
Source system PATH
Bin Paths
npm /home/myuser/.local/share/zed/node/node-v24.11.0-linux-x64/bin/npm
npx /home/myuser/.local/share/zed/node/node-v24.11.0-linux-x64/bin/npx
Installed true
Mode system_first
$ vp --version
vp v1.0.0-rc.0
Local vite-plus:
vite-plus v1.0.0-rc.0
Tools:
vite v8.3.0
rolldown v1.2.9
vitest v5.0.1
oxfmt v0.70.0
oxlint v1.85.0
oxlint-tsgolint v7.0.2002
tsdown v0.23.0
Environment:
Package manager npm default
Node.js v24.21.0
Used Package Manager
npm
Logs
$ npx vp pack
ℹ entry: src/index.ts
ℹ Build start
error: Build failed with 1 error:
[UNLOADABLE_DEPENDENCY] Could not load src/x.svg?raw
╭─[ src/index.ts:1:17 ]
│
1 │ import svg from "./x.svg?raw";
│ ──────┬──────
│ ╰──────── No such file or directory (os error 2)
───╯
at aggregateBindingErrorsIntoJsError (file:///tmp/vp-issue-repro/verify/vp-raw-repro/node_modules/vite-plus/node_modules/vite/dist/rolldown/shared/error-CGhV1ebk.mjs:48:18)
at unwrapBindingResult (file:///tmp/vp-issue-repro/verify/vp-raw-repro/node_modules/vite-plus/node_modules/vite/dist/rolldown/shared/error-CGhV1ebk.mjs:18:128)
at #build (file:///tmp/vp-issue-repro/verify/vp-raw-repro/node_modules/vite-plus/node_modules/vite/dist/rolldown/shared/rolldown-DZGaRc5R.mjs:133:34)
at async build (file:///tmp/vp-issue-repro/verify/vp-raw-repro/node_modules/vite-plus/node_modules/vite/dist/rolldown/index.mjs:48:22)
at async Promise.all (index 0)
at async buildSingle (file:///tmp/vp-issue-repro/verify/vp-raw-repro/node_modules/vite-plus/node_modules/vite/dist/tsdown/build-JVmLFaZt-BN9yuB6k.js:6380:19)
at async Promise.all (index 0)
at async buildWithConfigs (file:///tmp/vp-issue-repro/verify/vp-raw-repro/node_modules/vite-plus/node_modules/vite/dist/tsdown/build-JVmLFaZt-BN9yuB6k.js:6327:18)
at async CAC.<anonymous> (file:///tmp/vp-issue-repro/verify/vp-raw-repro/node_modules/vite-plus/dist/pack-bin.js:87:2)
at async runCLI (file:///tmp/vp-issue-repro/verify/vp-raw-repro/node_modules/vite-plus/dist/pack-bin.js:93:3)
Validations
- Read the Contributing Guidelines.
- Check that there isn't already an issue for the same bug.
- Confirm this is a Vite+ issue and not an upstream issue (Vite, Vitest, tsdown, Rolldown, or Oxc).
- The provided reproduction is a minimal reproducible example.
- Ngôn ngữ chính
- Rust
- Star
- 6k
- Fork
- 274
- Merge trung bình
- 1 ngày 11 giờ
- Pull request đã merge (30 ngày)
- 206
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của voidzero-dev/vite-plus
-
`npx --package=vite-plus vp create` fails with exit 127 when npm is the chosen package managerĐang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
voidzero-dev/vite-plus#2970 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
pending triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
voidzero-dev/vite-plus#2882 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
voidzero-dev/vite-plus#2097 · 10 bình luận · 2 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Windows: PowerShell installer (1.1.0) does not add vite-plus\bin to user PATH — 'vp' not recognizedĐang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 30/100
voidzero-dev/vite-plus#2984 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
pending triage
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 40/100
voidzero-dev/vite-plus#2983 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của voidzero-dev/vite-plus
Issue tương tự
-
C-bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
rust-lang/rust-analyzer#23501 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Streamable HTTP client: a 401 or 403 with a JSON-RPC error body and no WWW-Authenticate loses its HTTP statusCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mởbug P2 ready for work T-security T-transport
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
modelcontextprotocol/rust-sdk#1339 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
scripts/gen-gallery.py:118: a ready session now reports in_progress, so SESSION_READY_OLD can goĐang mởnightly-audit
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
antithesishq/snouty#396 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
French BIP39 wordlist starts with a UTF-8 BOM, so generated French mnemonics carry U+FEFF and derive a non-canonical seedCó thể đã có người làm @Kshot3000 đã nhận hôm nay. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 91/100
ergoplatform/sigma-rust#976 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày