-
Notifications
You must be signed in to change notification settings - Fork 5.2k
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
Absolute imports do not work correctly #25691
Comments
I can not reproduce the issue that you are describing, however I have some ideas that may be able to help you. Firstly, this what I am trying: // a/deno.json
{
"imports": {
"react": "npm:react"
}
} // a/main.ts
await import("../b/mod.ts"); // b/mod.ts
import react from "react";
console.log(react); Then when I run
So this is working. However, if you move the
This happens because Deno resolves the config file only from the entrypoint, not from all files in your graph. What you want is a workspace. This is a collection of multiple packages, that all have their own import maps. And example how this could look in your example: // deno.json
{
"workspace": ["./a", "./b"]
} // a/deno.json
{} // b/deno.json
{
"imports": {
"react": "npm:react"
}
} Do let me know if this helps. If your issue is resolved, please close the issue. |
Thanks @lucacasonato I resolved it by using the old trick with deps.ts, the only cons is that users also will have to use deps.ts in their project if they'll want to use my library But in a ideal way I would expect it to work similar to how node resolves the dependencies Because at the moment to build a library similar to Next.js for example is super hard in deno, because your library should be able to import user dependencies not from your library, otherwise users will not be able to add other imports than the ones you have in your library I'll try to create a repo that reproduces the issue, Thanks |
Yes, please create a reproduction. |
@lucacasonato Also as I said making this a workspace is not a posibility) even if it look like a workspace |
I don't understand. Are you saying your user would be running in The latter is not a supported use case for config file auto discovery - you have to then pass the config file from |
No as you can see in the readme user just changes directory to B but the entry point is A , in B it just runs a command from A) Btw were you able to reproduce using the repo I shared? |
And I cant pass a config because this is a dynamic import in the code as you can see in the repo I shared Also I cant pass a config because if B has a import in config but A not and uses another lib then that again would not work As you mentioned in node this is autodiscovery, thats what I kinda need |
And no is not a circular dependency as you can see in the example there is no circula deps, the code just uses a diferent CWD |
If the user wants to run code in If they do not do this we will discover the config file based on the entrypoint (in a/), and thus use the config file in a/. |
That I think is not correct behavior Which also means that there is no concept of peerDependencies and also you may run in problems like 2 different versions of react being used in same project basically if you are required to have react in both projects |
The problem I described above gets resolved only by using the deps.ts strategy And that leads us to the fact that in Deno there is no concept of peerDependencies) |
BTW is there a plan to support recursive dependency resolve? which is kinda what can fix this issue same as Node does? |
Version: Deno 1.46.3
I'm getting this error , when importing a file using dynamic import
How to reproduce:
let's say I have folder A which is a deno project and has a deno.json file
and then I have project B which also have a deno.json file
Now in project A in some file I'm using a dynamic import I'm trying to import a file from project B and that file in project B has (import react from 'react') inside
Now I have in both projects in deno.json in imports section this "react": "npm:[email protected]"
But even that doesn't help and I get the error that it is a relative import and react needs to be prefixed
But why is that if both projects have the dependency in the imports?
Is that I'm using a dynamic import with a absolte path in it?
like that
And the in that absolutePathToFile in that file I have (import react)
The text was updated successfully, but these errors were encountered: