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

data-url modules fail to import #207

Open
LorisSigrist opened this issue Jan 30, 2024 · 0 comments
Open

data-url modules fail to import #207

LorisSigrist opened this issue Jan 30, 2024 · 0 comments

Comments

@LorisSigrist
Copy link

Environment

Node.js v21.2.0

Reproduction

Self contained snippet:

import jiti from 'jiti'

const moduleAsText = "export default 42"
const dataUrl = "data:text/javascript;base64," + btoa(moduleAsText)

const nativeImport = await import(dataUrl)
console.log(nativeImport.default) // prints 42

const withJiti = jiti(import.meta.filename)(dataUrl)//Throws "MODULE_NOT_FOUND" error
console.log(withJiti.default)

Describe the bug

jiti fails to import modules from data-urls, which is supported by node's native import

Additional context

I tested both base64 encodings and text/javascript encoding, neither worked.
Peering at the source-code there doesn't seem to be any handling for this yet. Would you be interested in supporting this?

We discovered this in opral/monorepo#2133, where a vite-plugin broke because of this.

Logs

node:internal/modules/cjs/loader:1144
  const err = new Error(message);
              ^

Error: Cannot find module 'data:text/javascript;base64,ZXhwb3J0IGRlZmF1bHQgNDI='
Require stack:
- /Users/***/dev/jiti-debug/index.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1144:15)
    at Function.resolve (node:internal/modules/helpers:187:19)
    at _resolve (/Users/***/dev/jiti-debug/node_modules/.pnpm/jiti@1.21.0/node_modules/jiti/dist/jiti.js:1:251148)
    at jiti (/Users/***/dev/jiti-debug/node_modules/.pnpm/jiti@1.21.0/node_modules/jiti/dist/jiti.js:1:253746)
    at file:///Users/***/dev/jiti-debug/index.js:11:13 {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/Users/***/dev/jiti-debug/index.js' ]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant