Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ellemedit opened this issue Apr 4, 2024 · 8 comments
Closed
Labels
bug Something isn't working linear Created by Linear-GitHub Sync

Comments

@ellemedit
Copy link

ellemedit commented Apr 4, 2024

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 ellemedit added bug Something isn't working linear Created by Linear-GitHub Sync labels Apr 4, 2024
@ellemedit ellemedit changed the title [BUG] importing unexported member of @sei-js/proto [BUG] @sei-js/cosmjs package importing unexported member of @sei-js/proto Apr 4, 2024
@codebycarson
Copy link
Collaborator

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

@ellemedit
Copy link
Author

ellemedit commented Apr 5, 2024

@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

@ellemedit
Copy link
Author

@codebycarson could you check it?

@seangeng
Copy link

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

@besated besated closed this as completed Apr 10, 2024
@ellemedit
Copy link
Author

@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
Copy link
Author

ellemedit commented Apr 11, 2024

@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

@codebycarson
Copy link
Collaborator

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.

@ellemedit
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working linear Created by Linear-GitHub Sync
Projects
None yet
Development

No branches or pull requests

4 participants