sei-protocol/sei-js

[BUG] `@sei-js/cosmjs` package importing unexported member of @sei-js/proto

Closed this issue · 8 comments

Seid version

build time error (next.js):

../../node_modules/@sei-js/cosmjs/dist/esm/utils/serialize.js:9:10
Module not found: Package path ./types/cosmos/tx/v1beta1/tx is not exported from package /../node_modules/@sei-js/proto (see exports field in /../node_modules/@sei-js/proto/package.json)

the line is:

var _tx = require('@sei-js/proto/types/cosmos/tx/v1beta1/tx');

and the @sei-js/proto/package.json:

  "exports": {
    ".": {
      "import": "./dist/esm/index.js",
      "require": "./dist/cjs/index.js",
      "types": "./dist/types/index.d.ts"
    }
  }

It only export top level index.* module. So bundlers cannot build this.

SeiJS package & version
@sei-js/cosmjs@1.0.1 @sei-js/proto@3.0.1

@ellemedit can you try bumping your @sei-js/proto to version 4+?

@ellemedit can you try bumping your @sei-js/proto to version 4+?

I don't use @sei-js/proto directly, it's dependency of @sei-js/cosmjs. So I can try with custom resolutions.

And it looks like it works. Thank you. (Oops, I didn't check correctly)

Update:

I tried with @sei-js/proto@internal-vm and checked package.json:

  "exports": {
    ".": {
      "import": "./dist/esm/codegen/index.js",
      "require": "./dist/cjs/codegen/index.js",
      "types": "./dist/types/codegen/index.d.ts"
    },
    "./types/*": "./dist/types/codegen/*"
  }
Screenshot 2024-04-05 at 13 45 57

But it just a type definition file which is not needed for pure commonjs/esm itself. I think require means a commonjs/esm module not type defs. But there isn't a thing or module for the required path.

I attached import trace for more clues:


../../node_modules/@sei-js/cosmjs/dist/esm/utils/serialize.js:9:10
Module not found: Can't resolve '@sei-js/proto/types/cosmos/tx/v1beta1/tx'
Import trace for requested module:
../../node_modules/@sei-js/cosmjs/dist/esm/utils/index.js
../../node_modules/@sei-js/cosmjs/dist/esm/index.js

@codebycarson could you check it?

@ellemedit looks like I had the same issue - did you manage to resolve it?

@besated @codebycarson // it wasn't fixed.

In latest @sei-js/cosmjs@1.0.4 not able to import package too like:

Failed to compile.
../../node_modules/@sei-js/cosmjs/dist/esm/utils/serialize.js:2:0
Module not found: Package path ./dist/types/codegen/cosmos/tx/v1beta1/tx is not exported from package /home/runner/work/wallet-workspace/wallet-workspace/node_modules/@sei-js/proto (see exports field in /home/runner/work/wallet-workspace/wallet-workspace/node_modules/@sei-js/proto/package.json)

@ellemedit looks like I had the same issue - did you manage to resolve it?

yes, current workaround script something like:

var fs = require("fs");
var path = require("path");

var targetFiles = [
  "./node_modules/@sei-js/cosmjs/dist/cjs/utils/serialize.js",
  "./node_modules/@sei-js/cosmjs/dist/esm/utils/serialize.js",
];

const asIs = "require('@sei-js/proto/types/cosmos/tx/v1beta1/tx')";
const toBe = "require('cosmjs-types/cosmos/tx/v1beta1/tx');";
targetFiles.forEach((file) => {
  const filePath = path.join(__dirname, "YOUR PATH", file);
  console.log("patch file path", filePath);
  const fileContents = fs.readFileSync(filePath, {
    encoding: "utf-8",
  });
  var result = fileContents.replace(asIs, toBe);
  fs.writeFileSync(filePath, result);
});

with postinstall hook. @seangeng

Hey @ellemedit @seangeng , this is fixed in version 1.0.5 onwards.

Turns out that serialize function was importing "SignDoc" from @sei-js/proto, however it was importing the typescript type instead of the actual class itself. This has been resolved in the latest version of @sei-js/cosmjs.

Apologies for the issues here.

@codebycarson thank you for supporting! I see my CI/CD building properly.