NestarZ
NestarZ6mo ago

How to apply @deno-types on a dynamic import

// @deno-types="npm:@types/react-dom@18/client"
const { hydrateRoot: hydrate } = (await import("react-dom/client")).default;
// @deno-types="npm:@types/react-dom@18/client"
const { hydrateRoot: hydrate } = (await import("react-dom/client")).default;
Is not working, how to apply @Deno-types on a dynamic import ? I get this error: Check file:///Users/code/bureau/mod.ts error: Uncaught Error: Failed resolving package subpath './client' for '/Users/Library/Caches/deno/npm/registry.npmjs.org/react-dom/18.2.0/package.json': [ERR_PACKAGE_PATH_NOT_EXPORTED] Package subpath './client' is not defined for types by "exports" in '/Users/Library/Caches/deno/npm/registry.npmjs.org/react-dom/18.2.0/package.json' imported from '/Users/code/bureau/src/lib.ts'
2 Replies
Deno AI Helper
Deno AI Helper6mo ago
I wasn't able to find the answer to your question in the official Deno documentation. However, based on the code snippet and error message you provided, it seems like there might be an issue with the way the package subpath is being resolved. The @deno-types directive is used to associate TypeScript declaration files with JavaScript files. However, it is typically used with static imports rather than dynamic ones. The syntax you've used in the comment above the import statement is intended for static imports. For dynamic imports, Deno does not currently support the @deno-types directive in the same way as it does with static imports. This means that you cannot directly apply TypeScript declaration files to dynamic imports using @deno-types. The error message you're seeing suggests that there's a problem with resolving the package subpath './client' for the 'react-dom' package. This could be related to the way the package is structured or how Deno is trying to resolve the module. Please note that this advice is not based on the Deno documentation, and I would advise you to double-check the accuracy of the advice given. Since dynamic imports with @deno-types are not directly supported, you might need to find an alternative approach to type your dynamic imports, such as using a separate TypeScript declaration file or manually declaring the module types.
NestarZ
NestarZ6mo ago
Can an human confirm Deno dont support dynamic imports for added types ? Should an issue be open ? ??