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

new URL('.', import.meta.url) throws EISDIR error during build #7364

Closed
7 tasks done
fend25 opened this issue Mar 17, 2022 · 2 comments
Closed
7 tasks done

new URL('.', import.meta.url) throws EISDIR error during build #7364

fend25 opened this issue Mar 17, 2022 · 2 comments

Comments

@fend25
Copy link

fend25 commented Mar 17, 2022

Describe the bug

Demo repo: https://github.com/fend25/vite_import_meta_url_dot

TL;DR: new URL('.', import.meta.url) throws vite:asset-import-meta-url EISDIR error during build.

First of all I want to thank you for such good bundler. It's a huge work and I guess it does and will help people a lot. And while working with this I faced with one strange issue: in build mode (yarn build in repo) the new URL('.', import.meta.url) expression throws such error to the terminal:

vite v2.8.6 building for production...
✓ 2 modules transformed.
[vite:asset-import-meta-url] EISDIR: illegal operation on a directory, read
file: /Users/user/tmp/vite_importmetaurl_dot/main.js
error during build:
Error: EISDIR: illegal operation on a directory, read
error Command failed with exit code 1.

In dev mode it works, but one way or another it requires Vite config fine tuning:

{
  optimizeDeps: {
    esbuildOptions: {
      target: 'es2020'
    }
  },
  build: {
    target: 'es2020'
  }
}

Want to mention PR #7279. And maybe it requires to bump the default target versions or clarify it in the documentation a bit louder...

Possible workaround - place for discussion

Since I have no idea what the production build with such expression should work in browser, and I can refer only to the dev environment and the Node.js behaviour, I have come up with such "workaround":

const pathname = new URL(import.meta.url).pathname
const result = pathname.substring(0, pathname.lastIndexOf('/') + 1)

It gives same result as new URL('.', import.meta.url) in dev mode and in the Node.js (assuming {type: "module"} of course)

Reproduction

https://github.com/fend25/vite_import_meta_url_dot

System Info

System:
    OS: Linux 4.15 Ubuntu 18.04.6 LTS (Bionic Beaver)
    CPU: (6) x64 Intel(R) Core(TM) i5-9400F CPU @ 2.90GHz
    Memory: 2.81 GB / 7.79 GB
    Container: Yes
    Shell: 4.4.20 - /bin/bash
  Binaries:
    Node: 16.13.2 - /usr/bin/node
    Yarn: 1.22.17 - /usr/bin/yarn
    npm: 8.1.2 - /usr/bin/npm
  Browsers:
    Chrome: 99.0.4844.51
  npmPackages:
    vite: ^2.8.0 => 2.8.6

Used Package Manager

yarn

Logs

vite v2.8.6 building for production...
✓ 2 modules transformed.
[vite:asset-import-meta-url] EISDIR: illegal operation on a directory, read
file: /Users/user/tmp/vite_importmetaurl_dot/main.js
error during build:
Error: EISDIR: illegal operation on a directory, read
error Command failed with exit code 1.

Validations

@fend25 fend25 changed the title new URL('.', import.meta.url) throws build error when used in library new URL('.', import.meta.url) throws EISDIR error during build Mar 17, 2022
@tinydjp
Copy link

tinydjp commented Mar 18, 2022

just suffered same issue...it's raised in other packages' packageInfo.js, any workarounds?

@poyoho
Copy link
Member

poyoho commented Mar 21, 2022

fix: #7306 @bluwy

@bluwy bluwy closed this as completed Mar 21, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Apr 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants