sei-protocol/sei-js

Error: Cannot find module 'buffer/'

Closed this issue · 3 comments

cd3367 commented

@sei-js/core@3.0.1
packages/core/src/lib/utils/Hash.ts
line: 3
import { Buffer } from 'buffer/';

Error: Cannot find module 'buffer/'

The characters / is redundant ?

This is an issue with node polyfills on some environments. We currently have a ticket to bundle both @sei-js/core and @sei-js/react with webpack + babel instead of just babel to resolve these dependencies and will add an FAQ section to our docs. Is this a frontend or backend project you are working on? I'm happy to help resolve this issue for you. Typically you need to polyfill your app in this case.

cd3367 commented

I use it in typescript scripts with ESM.

run as:

npm run test

logs:

> ts-node-esm ./index.ts

Error: Cannot find module 'buffer/'
Require stack:
- ...\node_modules\@sei-js\core\dist\lib\utils\Hash.js
- ...\node_modules\@sei-js\core\dist\lib\utils\PubKeySecp256k1.js
- ...\node_modules\@sei-js\core\dist\lib\utils\signing.js
- ...\node_modules\@sei-js\core\dist\lib\utils\index.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:985:15)
...
 code: 'MODULE_NOT_FOUND',
  • index.ts
import { getStargateClient } from "@sei-js/core";

(async (): Promise<void> => {
const client = await getStargateClient("https://rpc.wallet.pacific-1.sei.io")
console.log(await client.getChainId())
})().catch(console.error);
  • package.json
{
  "name": "test",
  "version": "1.0.0",
  "description": "",
  "type": "module",
  "main": "index.ts",
  "scripts": {
    "test": "ts-node-esm ./index.ts"
  },
  "dependencies": {
    "@sei-js/core": "^3.0.1",
    "ts-node": "^10.9.1",
    "typescript": "^5.2.2"
  }
}
  • tsconfig.json
{
  "include": ["./index.ts"],
  "compilerOptions": {
    "module": "ESNext",
    "esModuleInterop": true,
    "skipLibCheck": true,
    "isolatedModules": true,
    "useDefineForClassFields": true,
    "allowJs": true,
    "moduleResolution": "Node",
    "target": "esnext",
    "lib": ["es2015", "dom", "esnext"],
    "types": ["node", "jsdom", "jest"],
    "baseUrl": "."
  }
}

This issue has been resolved in @sei-js/core and @sei-js/react version 3.0.2 and a section has been added to the FAQ's for this specific error.

https://docs.sei.io/develop/faq#resolving-referenceerror-process-is-not-defined