Fetch an imported asset URL responds with wrong content in dev mode
Open
Nobody has claimed this yet.
pending triage
- Dominant language
- TypeScript
- Stars
- 82.9k
- Forks
- 8.8k
- Avg merge
- 1d 23h
- Merged PRs (30d)
- 61
Description
Describe the bug
- Create an asset named
textwith contentI'm a text file. - Add the asset to
assetsIncludeinvite.config.js:assetsInclude: ["text"], - Import the asset:
import BinUrl from './text'; - Use
fetchto retrieve its content:fetch(BinUrl).then(response => response.text()).then(text => document.querySelector('#app').innerHTML = text);
In dev mode, the result is export default "/text"
In preview mode, the result is I'm a text file. (correct)
Reproduction
https://stackblitz.com/edit/vitejs-vite-whfdz5?file=main.js
Steps to reproduce
npm install && npm run dev
System Info
System:
OS: macOS 12.4
CPU: (4) x64 Intel(R) Core(TM) i7-7567U CPU @ 3.50GHz
Memory: 31.76 MB / 24.00 GB
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 18.16.0 - /usr/local/opt/node@18/bin/node
Yarn: 1.22.19 - /usr/local/bin/yarn
npm: 9.5.1 - /usr/local/opt/node@18/bin/npm
Browsers:
Chrome: 114.0.5735.133
Safari: 15.5
npmPackages:
vite: ^4.3.9 => 4.3.9
Used Package Manager
npm
Logs
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- 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.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked StackBlitz reproduction, then inspect vite.config.js and main.js while comparing npm run dev with preview mode. Reproduce the fetch and make the dev-mode response return the asset contents, matching the preview result instead of export default "/text".
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- build-system, devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100