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

[Bug]: dynamic import from 'data:' URI #12370

Closed
tbossi opened this issue Feb 11, 2022 · 3 comments · Fixed by #12392
Closed

[Bug]: dynamic import from 'data:' URI #12370

tbossi opened this issue Feb 11, 2022 · 3 comments · Fixed by #12392

Comments

@tbossi
Copy link
Contributor

tbossi commented Feb 11, 2022

Version

27.5.1

Steps to reproduce

  1. Clone my repo https://github.com/tbossi/jest-bug-data-uri-dynamic-import
  2. Run npm test
  3. The tests fail

Expected behavior

When running in ESM mode you can leverage dynamic import to load a module from a string by providing a data: URI instead of a file: uri.

For example:

const code = 'export const foo = 123'
const imported = await import(`data:text/javascript;charset=utf-8,${encodeURIComponent(code)}`)
console.log(imported.foo) // Should print 123

Actual behavior

Dynamic import throws an Error instead of importing from data URI.

Additional context

No response

Environment

System:
  OS: Windows 10 10.0.22000
  CPU: (12) x64 Intel(R) Core(TM) i7-10750H CPU @ 2.60GHz
Binaries:
  Node: 16.13.0 - C:\Program Files\nodejs\node.EXE
  npm: 8.1.0 - C:\Program Files\nodejs\npm.CMD
tbossi added a commit to tbossi/jest that referenced this issue Feb 15, 2022
tbossi added a commit to tbossi/jest that referenced this issue Feb 15, 2022
@SimenB
Copy link
Member

SimenB commented Feb 16, 2022

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

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

Successfully merging a pull request may close this issue.

2 participants