MeshJS / mesh

An open-source library to advance Web3 development on Cardano

Home Page:https://meshjs.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

typescript: Could not find a declaration file for module '@meshsdk/react'

joacohoyos opened this issue · comments

Hi! We are trying to use mesh, it seems to be working fine while running the app locally but we are getting the following error on the code editor and the type declarations are not working

image

I've created an issue about this bug before. Here's my temporary fix.

To get it working locally, you have to manually edit node_modules/@meshsdk/core/package.json and node_modules/@meshsdk/react/package.json. Then you can run a script so it gets done at build time in production as well. Run the scripts locally to fix type declarations.

Create a scripts folder in your root dir and create these two files:

// fix-meshsdk-core-typings.js
const fs = require('fs');
const path = require('path');

const filePath = path.resolve(__dirname, '../node_modules/@meshsdk/core/package.json');
const packageJson = require(filePath);

packageJson.exports['.']['types'] = './dist/index.d.ts';

fs.writeFileSync(filePath, JSON.stringify(packageJson, null, 2) + '\n');

and

// fix-meshsdk-typings.js
const fs = require('fs');
const path = require('path');

const filePath = path.resolve(__dirname, '../node_modules/@meshsdk/react/package.json');
const packageJson = require(filePath);

packageJson.exports['.']['types'] = './dist/index.d.ts';

fs.writeFileSync(filePath, JSON.stringify(packageJson, null, 2) + '\n');

Then in your package.json, add a postinstall script:

  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint",
    "postinstall": "node scripts/fix-meshsdk-typings.js && node scripts/fix-meshsdk-core-typings.js"
  },