-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
"Could not read from file …" error thrown when using ?url
and ?worker
suffixes inside 3rd party module
#10838
Comments
?url
and ?worker
suffixes inside 3rd party module?url
and ?worker
suffixes inside 3rd party module
Is there any update about this? |
In my case, I was updating to React PDF v7 and ran into this issue. What I ended up doing was including the transitive dependency / 3rd party module in our Vite config to also optimize it when using the export default defineConfig({
...
optimizeDeps: { include: ['pdfjs-dist'] },
}) |
I dived a bit into the bug and the problem is in this line:
If the file system resolve fails here, we just stay on the artificially produced path like:
Hence a fix would mean: resolve at this location the correct path to the worker file of the 3rd party module in the node_modules directory. It seems a code bit like this will work: file = tryFsResolve(file, fsResolveOptions) ?? tryOptimizedDepResolve(url, id) ?? file;
function tryOptimizedDepResolve(url, depId, fsResolveOptions) {
if (depsOptimizer?.isOptimizedDepFile(depId)) {
const depFile = cleanUrl(depId);
const info = optimizedDepInfoFromFile(depsOptimizer.metadata, depFile);
const depSrc = info.src;
if (depSrc) {
const resolvedFile = path.resolve(path.dirname(depSrc), url)
return tryFsResolve(file, fsResolveOptions);
}
}
return undefined;
} It is a similar flow like the existing tryOptimizedResolve but simplified. I'll check if I can make a change to Vite and test it locally. |
I prepared a fix which works nicely for my library at #16418
|
Running into the same issue, would love to see this fixed.. |
Describe the bug
Getting module URL in our own code like so:
works fine, but if that very same line is placed in
node_modules/module-1/index.js
, build crashes:At the same time, I was not able to find any mention regarding these suffixed working only on limited subset of modules when reading the following page: https://vitejs.dev/guide/assets.html
Reproduction
https://github.com/wojtekmaj/vite-url-suffix-bug
Steps to reproduce
yarn
yarn copy-packages
(to replace symlinks in node_modules with actual modules, since they come from internal workspace)yarn dev
System Info
System: OS: macOS 13.0 CPU: (8) arm64 Apple M1 Pro Memory: 457.75 MB / 16.00 GB Shell: 5.8.1 - /bin/zsh Binaries: Node: 18.12.0 - /usr/local/bin/node Yarn: 3.2.4 - /usr/local/bin/yarn npm: 8.19.2 - /usr/local/bin/npm Browsers: Chrome: 107.0.5304.87 Firefox: 106.0.3 Safari: 16.1 npmPackages: vite: ^3.2.3 => 3.2.3
Used Package Manager
yarn
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: