bufbuild / protobuf-es

Protocol Buffers for ECMAScript. The only JavaScript Protobuf library that is fully-compliant with Protobuf conformance tests.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

package import key leads to CJS code via proxy

dckc opened this issue Β· comments

Hi! πŸ‘‹

Firstly, thanks for your work on this project! πŸ™‚

Today I used patch-package to patch @bufbuild/protobuf@1.5.0 for the project I'm working on.

I'm using endo to bundle some generated code. It looked at exports and used the import key, which got proxy/index.js, which led to CJS code. Is that by design? It seems odd.

Here is the diff that solved my problem:

diff --git a/node_modules/cosmic-proto-es/node_modules/@bufbuild/protobuf/package.json b/node_modules/cosmic-proto-es/node_modules/@bufbuild/protobuf/package.json
index 81b39d9..177f75e 100644
--- a/node_modules/cosmic-proto-es/node_modules/@bufbuild/protobuf/package.json
+++ b/node_modules/cosmic-proto-es/node_modules/@bufbuild/protobuf/package.json
@@ -27,7 +27,7 @@
     ".": {
       "module": "./dist/esm/index.js",
       "require": "./dist/cjs/index.js",
-      "import": "./dist/proxy/index.js"
+      "import": "./dist/esm/index.js"
     }
   },
   "devDependencies": {

This issue body was partially generated by patch-package.

Hi @dckc. We are actually in the process of fixing this issue with #611. You can check out that issue for more context.

Basically, the export map will become:

  "exports": {
    ".": {
      "node": {
        "import": "./dist/proxy/index.js",
        "require": "./dist/cjs/index.js"
      },
      "module": "./dist/esm/index.js",
      "import": "./dist/esm/index.js",
      "require": "./dist/cjs/index.js"
    }
  },

We've actually already landed this change in Connect-ES (#921) and will be landing the same change in this repo. Hope to get this landed within the next day or two.

@dckc this should hopefully be fixed in v1.5.1 released today. The PR is here. Going to close this, but if you are still seeing issues, feel free to reopen.