Cannot find module '@icp-sdk/core/principal' or its corresponding type declarations

No stress, I know the answer! :wink:

I’m sharing this post for “documentation” purposes, as I faced it again and, in case any developers in the ecosystem encounter the following error on the forum after migrating to @icp-sdk/core, @icp-sdk/canisters, or the latest version of @dfinity/utils.

node_modules/@junobuild/ic-client/declarations/satellite/satellite.did.d.ts:3:32 - error TS2307: Cannot find module '@icp-sdk/core/principal' or its corresponding type declarations.
  There are types at '/Users/daviddalbusco/projects/juno/create-juno/node_modules/@icp-sdk/core/lib/esm/principal/index.d.ts', but this result could not be resolved under your current 'moduleResolution' setting. Consider updating to 'node16', 'nodenext', or 'bundler'.

3 import type { Principal } from '@icp-sdk/core/principal';

or

node_modules/@junobuild/ic-client/declarations/satellite/satellite.did.d.ts:2:26 - error TS2307: Cannot find module '@icp-sdk/core/candid' or its corresponding type declarations.
  There are types at '/Users/daviddalbusco/projects/juno/create-juno/node_modules/@icp-sdk/core/lib/esm/candid/index.d.ts', but this result could not be resolved under your current 'moduleResolution' setting. Consider updating to 'node16', 'nodenext', or 'bundler'.

2 import type { IDL } from '@icp-sdk/core/candid';

or

node_modules/@junobuild/ic-client/declarations/satellite/satellite.did.d.ts:1:34 - error TS2307: Cannot find module '@icp-sdk/core/agent' or its corresponding type declarations.
  There are types at '/Users/daviddalbusco/projects/juno/create-juno/node_modules/@icp-sdk/core/lib/esm/agent/index.d.ts', but this result could not be resolved under your current 'moduleResolution' setting. Consider updating to 'node16', 'nodenext', or 'bundler'.

1 import type { ActorMethod } from '@icp-sdk/core/agent';
2 Likes

The issue can occur when bundling an application or library written in TypeScript that uses a legacy module resolution, such as "moduleResolution": "node". Such setups may not support multi-entry libraries that define paths with "imports" and "exports" fields in their package.json.

To resolve this issue, you can either update your module resolution to a newer Node version or, if you’re using a bundler (which is often the case when developing apps), set "moduleResolution": "bundler".

{
  "compilerOptions": {
    "module": "esnext",
    "target": "esnext",
    "lib": ["esnext", "dom"],
    "strict": true,
    "noImplicitAny": false,
    "esModuleInterop": true,
    "moduleResolution": "bundler", // <----- For example
    "outDir": "dist",
    "resolveJsonModule": true
  },
}

Reference: TSConfig Reference - Docs on every TSConfig option

1 Like

For reference, the ICP JS Docs cover this issue in two places:

3 Likes

Told you, can’t remember the url :wink:

Joke aside, awesome :+1:!

1 Like