mesh icon indicating copy to clipboard operation
mesh copied to clipboard

error TS2307: Build:Cannot find module '@mesh/core' or its corresponding type declarations.

Open matbech opened this issue 1 year ago • 2 comments

I get the following compiler errors with Visual Studio

node_modules\@meshsdk\core\dist\common\constants.d.ts(1,21): error TS2307: Build:Cannot find module '@mesh/core' or its corresponding type declarations.
node_modules\@meshsdk\core\dist\common\constants.d.ts(2,31): error TS2307: Build:Cannot find module '@mesh/core' or its corresponding type declarations.
node_modules\@meshsdk\core\dist\common\contracts\fetcher.d.ts(1,100): error TS2307: Build:Cannot find module '@mesh/common/types' or its corresponding type declarations.

If I replace all the @mesh imports in constants.d.ts with relative paths:

import { csl } from '../core';

it does work as expected.

Another workaround is to add a module alias as following to tsconfig.json:

	"compilerOptions": {
		"paths": {
			"@mesh/*": [ "./node_modules/@meshsdk/core/dist/*" ]
		}
	},

But it might be better to relative paths inside the .ts files.

matbech avatar Dec 18 '23 00:12 matbech

The use of out-of-band module aliasing (i.e. @mesh/*) also prevents Deno users from being able to click through to the type of interest within their IDE in cases where those types are imported using links which depend on these aliases. For example, within transaction.service.d.ts:

import type {
  Action,
  Asset,
  Data,
  Era,
  Mint,
  Protocol,
  PlutusScript,
  PoolParams,
  Recipient,
  Token,
  UTxO,
} from "@mesh/common/types";

This may affect other tooling too, since the aliasing config has to be specified out-of-band (outside ESM) separately for each tool that needs it; hence why you have separate config for this in tsconfig.json and vite.config.js.

dchambers avatar May 25 '24 16:05 dchambers

So I just switched to Node.js so I could use @meshsdk/mesh-csl, and I hit the same aliasing issues when using tsc to compile my TypeScript code. The solution I ended up going with was to have tsc ignore the library errors with:

"skipLibCheck": true,

dchambers avatar May 29 '24 20:05 dchambers

Packaging has been updated entirely since V1.6, please re-open if issue persists.

Side note, everything is now packaged in @meshsdk/core, if you need some csl specific function, now it is exported at @meshsdk/core-csl

HinsonSIDAN avatar Aug 16 '24 07:08 HinsonSIDAN