foobar
foobar11mo ago

npm import : class is not found but it is well declared in node_module

I try to use Tatum SDK in deno (https://github.com/tatumio/tatum-js). I pick up the easiest code example https://docs.tatum.io/ I try 2 ways of imports of tatum library but I have different errors in both ways. 1. with npm don't recognize TatumSDK in import (but in node_modules it is exported in service/tatum). How can I tell the owner to slighty modify his code in order that TatumSDK is recognize (Ethereum, Network are recognized) ?
import { Ethereum, Network, TatumSDK } from "npm:@tatumio/tatum";

const tatum = await TatumSDK.init<Ethereum>({ network: Network.ETHEREUM });
const latestBlock = await tatum.rpc.blockNumber();
console.log(`Latest block is ${latestBlock.result}`);
tatum.destroy();
import { Ethereum, Network, TatumSDK } from "npm:@tatumio/tatum";

const tatum = await TatumSDK.init<Ethereum>({ network: Network.ETHEREUM });
const latestBlock = await tatum.rpc.blockNumber();
console.log(`Latest block is ${latestBlock.result}`);
tatum.destroy();
2. with esm Library BigNumber.js has a version for deno ! error: Uncaught (in promise) TypeError: R.BigNumber is not a constructor
// BigNumber.js has a version for deno !
// error: Uncaught (in promise) TypeError: R.BigNumber is not a constructor
import { Ethereum, Network, TatumSDK } from "https://esm.sh/@tatumio/tatum";

// fake call to prevent error
window.location = { hostname: "fake" };

const tatum = await TatumSDK.init<Ethereum>({ network: Network.ETHEREUM });
const latestBlock = await tatum.rpc.blockNumber();
console.log(`Latest block is ${latestBlock.result}`);
tatum.destroy();
// BigNumber.js has a version for deno !
// error: Uncaught (in promise) TypeError: R.BigNumber is not a constructor
import { Ethereum, Network, TatumSDK } from "https://esm.sh/@tatumio/tatum";

// fake call to prevent error
window.location = { hostname: "fake" };

const tatum = await TatumSDK.init<Ethereum>({ network: Network.ETHEREUM });
const latestBlock = await tatum.rpc.blockNumber();
console.log(`Latest block is ${latestBlock.result}`);
tatum.destroy();
4 Replies
Deno AI Helper
Deno AI Helper11mo ago
When you're encountering issues with importing npm packages in Deno, there are a few things to consider based on the documentation. Issues with npm imports in Deno The documentation states that Deno only supports the node16 module resolution. If you're facing issues where a class or function is not found, it could be due to incorrect types provided under the node16 module resolution for imports from ESM. This can result in deno check reporting type errors that tsc does not report. To verify if the issue is related to node16 module resolution, you can check if the error also occurs with tsc --module node16 and "type": "module" in package.json, or by consulting the Are the types wrong? website, particularly the "node16 from ESM" row. If you find that the package does not support TypeScript's node16 module resolution, you can: 1. Open an issue at the issue tracker of the package about the problem and perhaps contribute a fix. 2. Use a CDN that rebuilds the packages for Deno support, instead of an npm: identifier. 3. Ignore the type errors in your codebase with // @ts-expect-error or // @ts-ignore. Including Node types If the npm package you're trying to use references Node-specific types like Buffer, you'll need to add a types reference directive to the @types/node package:
/// <reference types="npm:@types/node" />
/// <reference types="npm:@types/node" />
Specific Issues with Tatum SDK 1. With npm: If TatumSDK is not recognized during import, but other classes like Ethereum and Network are, it could be due to the way the package exports its modules under the node16 resolution. You can suggest to the package owner to check their package's compatibility with node16 module resolution and make necessary
Are The Types Wrong?
Tool for analyzing TypeScript types of npm packages
Deno AI Helper
Deno AI Helper11mo ago
adjustments. 2. With esm.sh: For the error related to BigNumber, it seems like there might be an issue with the way the package is being imported or constructed. Since BigNumber.js has a version for Deno, you might want to ensure that you're importing the correct version that's compatible with Deno. Also, check if there are any specific instructions for using BigNumber.js with Deno that you need to follow. Remember to check the permissions required for running your script, as Deno is secure by default and requires explicit permissions to access the network, file system, etc. For further assistance, you might want to refer to the documentation for the specific package you're using, as well as Deno's documentation on npm specifiers and [import maps](https://deno.land/manual/linking
marvinh.
marvinh.11mo ago
That is a bug in deno. The TatumSDK export should definitely be there. Can you file an issue here https://github.com/denoland/deno/issues/new?assignees=&labels=&projects=&template=bug_report.md&title= ?
GitHub
Build software better, together
GitHub is where people build software. More than 100 million people use GitHub to discover, fork, and contribute to over 420 million projects.
From An unknown user
From An unknown user
From An unknown user

Did you find this page helpful?