Closed Penguinlay closed 2 years ago
Have same problem
"?raw" is not work on dynamic import in production mode, but it's work on dev mode.
The main code to load the file:
I think there are two important factors here.
First, we should be able to trust that if our app works in dev, it should work in production build as well.
This bug is kind of an edge case, but also breaks this promise.
Second, this feature of using dynamic imports with markdown is an amazing tool when building an app based off folder based content a la NextJs or Astro but using Vite instead.
Have a same problem .
In production . 'xxx?.raw' can't work correctly .
May it's can provide own plugin-dynamic-import-vars
to fix the bug .
Waiting for a solution :-)
@sodatea is there anything any of us here can do to help the Vite team with this issue 😌 ?
You can submit a PR if you know the fix/enhancement for this issue/feature!
Fixed via #5545
Describe the bug
I want to dynamically import content from a Markdown file, and use them as string. I won't also know if the file exists or not. Thus, with @patak-js's help, I first created glob import of all the files in that folder and then customized the module created by glob import, by appending
?raw
to the import.During the development, this workaround works; however whenever those dynamically imports are triggered, I got a warning that Vite cannot analyze the dynamic import.
So, I wondered if it is because the custom append on line does not satisfy the dynamic import format requirement. I fixed the customization above to below and the warning disappeared!
However, in both of the above cases, I got the build error below.
I tried it out with both Vite
v2.0.5
andv2.2.3
, and the same behavior for both versions. How can I resolve this issue and let me know if you need any more information from me to reproduce the issue.Reproduction
https://github.com/Penguinlay/reproduction-viteDynamicImportBug
System Info
Output of
npx envinfo --system --npmPackages vite,@vitejs/plugin-vue --binaries --browsers
:Used package manager: yarn
v1.22.10
Logs
yarn cache clean; rm -rf node_modules; rm yarn.lock; yarn; yarn vite --debug
yarn cache clean; rm -rf node_modules; rm yarn.lock; yarn; yarn build --debug
Before submitting the issue, please make sure you do the following