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

import.meta.url transformation produces invalid file URL strings #4461

Closed
mdjermanovic opened this issue Apr 13, 2022 · 6 comments · Fixed by #4875
Closed

import.meta.url transformation produces invalid file URL strings #4461

mdjermanovic opened this issue Apr 13, 2022 · 6 comments · Fixed by #4875

Comments

@mdjermanovic
Copy link

Rollup Version

2.70.1

Operating System (or Browser)

Windows

Node Version (if applicable)

v16.14.0

Link To Reproduction

https://github.com/mdjermanovic/rollup-import-meta-url-repro

Expected Behaviour

import.meta.url to be transformed to an expression that always evaluates to valid URL strings.

Actual Behaviour

When __filename contains special characters or sequences such as %2F, new (require('u' + 'rl').URL)('file:' + __filename).href could be an invalid file URL string.

node:internal/modules/cjs/loader:1216
      throw new ERR_INVALID_ARG_VALUE('filename', filename,
      ^

TypeError [ERR_INVALID_ARG_VALUE]: The argument 'filename' must be a file URL object, file URL string, or absolute path string. Received 'file:///C:/milos/rollup-import-meta-url-repro/my%2Fdir/index.cjs'
    at new NodeError (node:internal/errors:371:5)
    at Function.createRequire (node:internal/modules/cjs/loader:1216:13)
    at Object.<anonymous> (C:\milos\rollup-import-meta-url-repro\my%2Fdir\index.cjs:5:28)
    at Module._compile (node:internal/modules/cjs/loader:1103:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1155:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
    at node:internal/main/run_main_module:17:47 {
  code: 'ERR_INVALID_ARG_VALUE'
}

Ref: eslint/eslint#15766

@fasttime
Copy link
Contributor

I can imagine a modest potential for misuse, considering that, for instance, file:/home/someuser/workspace/my_project/%2e%2e/%2e%2e/%2e%2e/%2e%2e/etc/hosts#foo=1/subfolder/index.js resolves to the same path as file:/etc/hosts (demo link).

@sveinnthorarins
Copy link

Ran into this problem today, can't run vite cause my project path contains a '#' symbol and vite is bundled with rollup.

Why is nobody taking a look at this?

@lukastaegert
Copy link
Member

PR welcome

@fasttime
Copy link
Contributor

@sveinnthorarins I could be wrong but your issue may be a different one as Rollup intentionally replaces some characters like "#" with underscores for compatibility across file systems. I went on and did a PR for the bug here.

@sveinnthorarins
Copy link

@fasttime Thanks for making the PR.

Yeah well, from tracking my problem and its error messages, the issue stated here (the poor transformation of import.meta.url into new URL(filePath).href) is my first and main concern.

The issue you're mentioning might then take on the mantle (of causing me problems) after this issue is fixed 😆 😳

@rollup-bot
Copy link
Collaborator

This issue has been resolved via #4875 as part of rollup@3.17.3. You can test it via npm install rollup.

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

Successfully merging a pull request may close this issue.

5 participants