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

Viem can not be compiled with node16/bundle module resolution by tsc #2621

Open
1 task done
mojtabast opened this issue Aug 16, 2024 · 4 comments
Open
1 task done

Comments

@mojtabast
Copy link

Check existing issues

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:

@mojtabast mojtabast changed the title Viem can not compile with node16/bundle module resolution using tsc Viem can not be compiled with node16/bundle module resolution by tsc Aug 27, 2024
@itslesther
Copy link

Any update/workaround on this issue?

@jxom
Copy link
Member

jxom commented Oct 10, 2024

"skipLibCheck": true

@mojtabast
Copy link
Author

mojtabast commented Oct 16, 2024

"skipLibCheck": true

@jxom
This is not a good recommendation since it reduces type accuracy. Another problem is for library authors, any library depends on viem which is publishing their package should tell "skipLibCheck": true to their users.

@jxom
Copy link
Member

jxom commented Oct 16, 2024

It's a workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants