-
Notifications
You must be signed in to change notification settings - Fork 5.6k
deno check error resolving package config for npm react jsx-runtime #18203
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
Comments
I've encountered this same issue. It is preventing me from switching from using esm.sh to using npm specifiers. Are there any plans to fix this issue anytime soon?
|
This is just #20455, which is on the roadmap but not currently being worked on. The following workaround doesn't work: // @deno-types="npm:@types/react@18"
import React from "npm:react@18";
// @deno-types="npm:@types/react-dom@18/server"
import { renderToString } from "npm:react-dom@18/server";
function Hello() {
return <div>Hello world!</div>;
}
console.log(renderToString(<Hello />)); because it doesn't apply to the |
What about adding a |
That would be better but I'm guessing people will regularly miss that they need to set that types option too. Then they'd only find out if they google the error and find issues like this one. Then we still have the problem that you'll need to add a bunch of these comments in any files that import react or other dependencies that have separate types. // @deno-types="npm:@types/<package>" I feel like it would be better to have a version mismatch in some cases than to have no types at all. I'd rather only have to add those comments in the case there is a mismatch issue than to need them for most modules. The way esm.sh picks the types to use seems to just work the way you would expect it to. I don't have to manually set or override types for any of my esm.sh dependencies. |
A nice general solution would be to extend our {
"compilerOptions": {
"types": [
"./types.d.ts",
"https://deno.land/x/[email protected]/types.d.ts",
{ "target": "https://deno.land/x/some_untyped_module/", "types": "npm:@types/some-untyped-module/" },
{ "target": "npm:react@18", "types": "npm:@types/react@18" },
{ "target": "npm:react@18/", "types": "npm:@types/react@18/" }
]
}
} This would be yet another, but meaningfully distinct way of adding types to untyped modules. In order of priority:
It would satisfy the need to out-scope It's comparable to adding the |
@nayeemrmn seems complex. That would require keeping the react version in sync in 5 places instead of once for |
I like the idea of it just being something you add to deno.json. although if we add it to the types array, it would be nicer if we could just add the string "npm:@types/[email protected]" without having to specify a target or have 2 entries like you do where one has a trailing slash. In package.json you would just add the types to your list of dependencies without having to specify they are the types for react. Ideally we would either not have to specify types or just have one place to specify them for the whole project. |
That's a good idea, since {
"compilerOptions": {
"types": [
"./types.d.ts",
"https://deno.land/x/[email protected]/types.d.ts",
// Will be used for any `npm:[email protected]/*`
"npm:@types/react@18"
]
}
} @dsherret WDYT? |
The only additional thing I would want is for it to be able to work with an import map, that way I could just specify the version there instead of having to update both deno.json and my import map to bump my react version. I think adding a types array entry like that would be the easiest way to do it as it would get rid of needing to add a bunch of deno-types comments all over your codebase. |
@nayeemrmn I like that too 👍 @KyleJune you can store the import map in a deno.json nowadays (just copy and paste the "imports" and "scopes" properties into the deno.json, delete the "importMap" property in deno.json, then delete the import map file). I don't think we could support this in an import map file because it would be non-standard. |
I assume {
"compilerOptions": {
"types": [
"./types.d.ts",
"https://deno.land/x/[email protected]/types.d.ts",
// If this resolves to `npm:@types/react@18`, it will be used for any `npm:[email protected]/*`
"@types/react"
]
},
"imports": {
"@types/react": "npm:@types/react@18"
}
} Though I wouldn't personally bother if they're in the same file anyway. |
As long as my bare specifier alias for npm specifier imports can get the types I'm good then. I just don't want to have to update all my files to use npm specifier imports with the version in it since that would make updates difficult. If types will still work for my bare specifiers and I put my import map in my deno.json, then I've got it where I could update my dependencies by only touching a single file. |
I like the idea of including the To me, assuming that I think a format more similar to import maps is more clear. {
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "npm:react",
"types": {
"npm:react": "npm:@types/react@18",
"https://deno.land/x/other-library/": "./my-custom-types.d.ts",
}
}
} |
FWIW, a view from the cheap seats from this relative newcomer: It seems a bit odd to put this in Perhaps an {
"imports": {
"react": "npm:react@^18.2"
},
"import-types": {
"react": "npm:@types/react@^18.2"
}
} The entry in
A couple of notes re that example:
Separately, having to repeat the version number is a maintenance chore (one that Node's {
"imports": {
"react": "npm:react@^18.2"
},
"import-types": {
"react": "npm:@types/react@infer"
}
} There, Deno would infer To me, that would be an excellent devex for these packages that don't directly provide types. (Using Apologies if any of this is unworkable in ways that would be obvious to someone more experienced with the project. |
One thing I missed in my comment above is that there already is a I think my |
This is now possible to specify via {
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "npm:react@^18.3",
"jsxImportSourceTypes": "npm:@types/react@^18.3"
}
} |
While importing the npm:@types packages as per #16653 silences errors from the language server when running deno check I see the following error:
However in react's package.json an entry for './jsx-runtime' exists:
Files to reproduce:
index.tsx:
deno.json:
The text was updated successfully, but these errors were encountered: