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
Fix Vite build bundling error about EISDIR on new URL('.', import.meta.url)
#637
Conversation
…ta.url)` Hi! Vite shows EISDIR error at `new URL('.', import.meta.url)` expression on build. Actually checking import.meta.url is not enough to fix this problem. The problem is when bundler tries to build the code in production build, in compile time it has no idea about how the expression `new URL('.', import.meta.url)` should be resolved in runtime. And it tries to read all the file and bake it inline in base64 form. And in case of `new URL('.', ...)` it tries to read the dir what is impossible and throws compile-time error EISDIR. So I created a workaround code which gives the same output in Vite dev and Node.js environments: ```js const filePathname = new URL(import.meta.url).pathname const folderPathname = filePathname.substring(0, filePathname.lastIndexOf('/')+1) ``` actually does literally the same as ```js new URL('.', import.meta.url) ``` Also closes polkadot-js/extension#1018
On bundlers, e.g. webpack, having the The path is used in detect - so it shows you exactly where duplicate packages are, without it you see a conflict, but have absolutely no information as to where it is and how to solve it. |
But it's strange... How can we make @polkadot/* packages family possible to compile via Vite or other bundlers, and not via Webpack only? |
The above is a Vite issue, it should handle TL;DR Bundlers are generally quite slow in making progress... Have not had a gap to look at the suggested solution as of yet. |
It is, and as you've mentioned, to merge a PR to bundler is a long-term work. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had to test it against a built API (verifying there) against a build webpack instance and it seems spot-on. Exceptionally weird as a bundler work-around.
So good! Thank you and I really appreciate it! |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Hi!
Vite shows EISDIR error at
new URL('.', import.meta.url)
expression on build.Actually checking import.meta.url is not enough to fix this problem.
The problem is when bundler tries to build the code in production build, in compile time it has no idea about how the expression
new URL('.', import.meta.url)
should be resolved in runtime. And it tries to read all the file and bake it inline in base64 form. And in case ofnew URL('.', ...)
it tries to read the dir what is impossible and throws compile-time error EISDIR.So I created a workaround code which gives the same output in Vite and Node.js environments:
actually does literally the same as
Regarding webpack - it's a bit more complicated.
Now webpack compiles
new URL('.', import.meta.url).pathname
to something like/1247de54f5a6c6dbd.js
.Obviously it doesn't make sense still
'.'
clearly describes desired result as a path to some folder. So current webpack behaviour is useless still it doesn't help to get a path to the package folder.But this is an obvious and strange workaround from the webpack. Because without such config option, webpack just compiles whole path to the lib folder on the compiling machine. There is a closed PR and such option may be switched on in webpack config:
With that option, workaround works really good and really provides a path to the folder (actually a plain '/', but it makes sense and it is the desired behaviour of
new URL('.', import.meta.url).pathname
expression).Without that option it compiles to something like `/Users/user/projects/project/node_modules/@polkadot/x-global'.
Also closes polkadot-js/extension#1018
BTW, @jacogr, could you please describe what the purpose of this code at all? I'm not sure why packages should provide information about themselves not via standard mechanics of import/require?