typescript: Could not find a declaration file for module '@meshsdk/react'
joacohoyos opened this issue · comments
Joaquin Hoyos (Clark) commented
Marty commented
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"
},