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

Cannot dynamically import uncached JSR module: "TypeError: Could not find constraint in the list of versions" #23965

Closed
alexgleason opened this issue May 23, 2024 · 5 comments · Fixed by #24928
Assignees
Labels
bug Something isn't working correctly jsr Issues or feature requests relating to JSR.io

Comments

@alexgleason
Copy link
Contributor

Version: Deno 1.43.4

I'm using a dynamic import to import a module based on an environment variable:

const Policy = (await import(Deno.env.get('DITTO_POLICY'))).default;
const policy = new Policy();

This allows users to have DITTO_POLICY=jsr:@gleasonator/policy@0.2.0, and it dynamically imports the module.

When I do that, I get this error:

TypeError: Could not find constraint in the list of versions: @gleasonator/policy@0.2.0

I am able to resolve that error by manually running deno cache jsr:@gleasonator/policy@0.2.0

Then it works. Because the module is available now. The error disappears. But I would like it to be automatic.

To solve this, I wondered if some sort of Deno.cache runtime API exists (it doesn't?). The other option is to run a Deno subcommand that calls the deno cache API.

It made me wonder, how does Deno resolve dynamic imports? Shouldn't we expect it to download and cache the module automatically like other imports? So it got me thinking that maybe this is a bug in Deno.

@alexgleason alexgleason changed the title Cannot dynamic import JSR module: "TypeError: Could not find constraint in the list of versions" Cannot dynamically import JSR module: "TypeError: Could not find constraint in the list of versions" May 23, 2024
@dsherret dsherret added bug Something isn't working correctly jsr Issues or feature requests relating to JSR.io labels May 23, 2024
@dsherret dsherret changed the title Cannot dynamically import JSR module: "TypeError: Could not find constraint in the list of versions" Cannot dynamically import uncached JSR module: "TypeError: Could not find constraint in the list of versions" May 23, 2024
@dsherret
Copy link
Member

There's code for it to cache bust and just work. It seems like it's not working with dynamic imports though.

@nandorojo
Copy link

I’m facing the same thing. Let me confirm that it’s due to dynamic imports (I believe it is).

@dsherret
Copy link
Member

Just a note that you can get around this by running with --reload

@alexgleason
Copy link
Contributor Author

I've still been manually running deno cache jsr:<package> for each of my new dynamic imports.

If there was even a Deno.cache runtime API that would let me cache the modules I need at startup that would be a big improvement.

I also don't necessarily want them in deno.lock.

@pomdtr
Copy link

pomdtr commented Jul 30, 2024

I found out that if the dynamic imports are statically analysable, the issue does not occur.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly jsr Issues or feature requests relating to JSR.io
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants