vite v4.4.11 building for production...
transforming...
✓ 689 modules transformed.
Could not resolve "../pkg-wasm" from "src/Craft.ts"
file: /Users/runner/work/ffxiv-best-craft/ffxiv-best-craft/src/Craft.ts
✓ built in 13.83s
error during build:
RollupError: Could not resolve "../pkg-wasm" from "src/Craft.ts"
at error (file:///Users/runner/work/ffxiv-best-craft/ffxiv-best-craft/node_modules/rollup/dist/es/shared/node-entry.js:2287:30)
at ModuleLoader.handleInvalidResolvedId (file:///Users/runner/work/ffxiv-best-craft/ffxiv-best-craft/node_modules/rollup/dist/es/shared/node-entry.js:24860:24)
at ModuleLoader.resolveDynamicImport (file:///Users/runner/work/ffxiv-best-craft/ffxiv-best-craft/node_modules/rollup/dist/es/shared/node-entry.js:24920:58)
at async file:///Users/runner/work/ffxiv-best-craft/ffxiv-best-craft/node_modules/rollup/dist/es/shared/node-entry.js:24807:32
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Error: Process completed with exit code 1.
[X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
[X] Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
Describe the bug
I want to build same code to different targets: Tauri or Web. In the project, some Rust code need to be compiled to native code or wasm.
In the front-end code, to tell what target we are building, I use the Env variables. I use something like this:
But when I set
VITE_MY_TARGET=tauri
, it fails to compile with:The
../pkg-wasm
not exist when I'm building fortauri
.Also tried this code:
Which can successfully built.
Since the document says "these env variables are statically replaced". I expect both of the codes should act as same?
Reproduction
https://github.com/Tnze/vite-issue-4782-minimal-reproducible-example
Steps to reproduce
pnpm run build
System Info
Used Package Manager
yarn
Logs
vite v4.4.11 building for production... transforming... ✓ 689 modules transformed. Could not resolve "../pkg-wasm" from "src/Craft.ts" file: /Users/runner/work/ffxiv-best-craft/ffxiv-best-craft/src/Craft.ts ✓ built in 13.83s error during build: RollupError: Could not resolve "../pkg-wasm" from "src/Craft.ts" at error (file:///Users/runner/work/ffxiv-best-craft/ffxiv-best-craft/node_modules/rollup/dist/es/shared/node-entry.js:2287:30) at ModuleLoader.handleInvalidResolvedId (file:///Users/runner/work/ffxiv-best-craft/ffxiv-best-craft/node_modules/rollup/dist/es/shared/node-entry.js:24860:24) at ModuleLoader.resolveDynamicImport (file:///Users/runner/work/ffxiv-best-craft/ffxiv-best-craft/node_modules/rollup/dist/es/shared/node-entry.js:24920:58) at async file:///Users/runner/work/ffxiv-best-craft/ffxiv-best-craft/node_modules/rollup/dist/es/shared/node-entry.js:24807:32 error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command. Error: Process completed with exit code 1.
Validations