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

Fetch an imported asset URL responds with wrong content in dev mode #13636

Open
7 tasks done
yume-chan opened this issue Jun 26, 2023 · 4 comments
Open
7 tasks done

Fetch an imported asset URL responds with wrong content in dev mode #13636

yume-chan opened this issue Jun 26, 2023 · 4 comments

Comments

@yume-chan
Copy link
Contributor

Describe the bug

  1. Create an asset named text with content I'm a text file.
  2. Add the asset to assetsInclude in vite.config.js: assetsInclude: ["text"],
  3. Import the asset: import BinUrl from './text';
  4. Use fetch to 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

  1. 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

@stackblitz
Copy link

stackblitz bot commented Jun 26, 2023

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@devjiwonchoi
Copy link

@yume-chan
Copy link
Contributor Author

yume-chan commented Jul 6, 2023

The asset file is in a dependency package I have no control. Also it works in Webpack and vite build.

@sapphi-red
Copy link
Member

related: #10123, #14850 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants