Closed
Description
Check existing issues
- I checked there isn't already an issue for the bug I encountered.
Viem Version
2.19.6
Current Behavior
Goes through this error:
node_modules/viem/_types/account-abstraction/accounts/types.d.ts:2:63 - error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("webauthn-p256")' call instead.
2 import type { SignReturnType as WebAuthnSignReturnType } from 'webauthn-p256';
~~~~~~~~~~~~~~~
node_modules/webauthn-p256/_types/types.d.ts:27:67 - error TS2536: Type '_K' cannot be used to index type 'fallback'.
27 [_K in Exclude<keys, keyof Item>]?: fallback extends object ? fallback[_K] : undefined;
~~~~~~~~~~~~
Found 2 errors in 2 files.
Errors Files
1 node_modules/viem/_types/account-abstraction/accounts/types.d.ts:2
1 node_modules/webauthn-p256/_types/types.d.ts:27
Expected Behavior
It should be compiled when module: node16
or module: esnext
and moduleResolution: bundler
enabled.
Steps To Reproduce
Try to run on my repo:
yarn
yarn run compile
Link to Minimal Reproducible Example
https://github.com/mojtabast/viem-tsc-compile-node16-issue
Anything else?
The problem is on node16
you can not import directly from a cjs module during ESM spec. it seems webauthn-p256
is cjs and somewhere you are importing a type from a cjs module:
import type { SignReturnType as WebAuthnSignReturnType } from 'webauthn-p256';
Although, typescript should differentiate a normal import and a type import, but it doesn't do that. You can follow some discussion around this here:
Metadata
Metadata
Assignees
Labels
No labels