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

Incompatibility since version 0.5.1 with commonjs modules #86

Closed
jrebmann opened this issue Mar 4, 2021 · 4 comments
Closed

Incompatibility since version 0.5.1 with commonjs modules #86

jrebmann opened this issue Mar 4, 2021 · 4 comments

Comments

@jrebmann
Copy link

jrebmann commented Mar 4, 2021

Problem:

I am building an executable from my Apollo application using the framework pkg. Since version 0.5.1 of ts-invariant, I get the following error message when launching the executable:

#> .\program.exe start
pkg/prelude/bootstrap.js:1244
throw error;
^
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /snapshot/program/node_modules/@ungap/global-this/cjs/index.js
require() of ES modules is not supported.
require() of /snapshot/program/node_modules/@ungap/global-this/cjs/index.js from /snapshot/program/node_modules/ts-invariant/lib/invariant.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /snapshot/program/node_modules/@ungap/global-this/package.json.

Interpretation:

I know that I don't get support for the framework pkg here. However, I am not sure if this is just a module integration error.

Unfortunately I cannot work with the current version of @apollo/client (with ts-invariant as dependency).

I would be very grateful for help with this problem.

Workaround:

I set the exact versions of @apollo/client and ts-invariant:

  "dependencies": {
    ...
    "@apollo/client": "3.3.3",
    "ts-invariant": "0.5.1",
    ...
  }
@benjamn
Copy link
Member

benjamn commented Mar 18, 2021

@CuddlySheep I believe this is fixed by #98?

@jrebmann
Copy link
Author

Looks very good, I will test it tomorrow. Thanks a lot for your help.

@jrebmann
Copy link
Author

So the bugfix seems to have worked. However, the fixed version is not yet released with the current version of @apollo/client@3.3.12.

There is still version 0.6.2 linked. Following shows the corresponding part of my package-lock.json.

"dependencies": {
    "@apollo/client": {
      "version": "3.3.12",
      "resolved": "https://registry.npmjs.org/@apollo/client/-/client-3.3.12.tgz",
      "integrity": "sha512-1wLVqRpujzbLRWmFPnRCDK65xapOe2txY0sTI+BaqEbumMUVNS3vxojT6hRHf9ODFEK+F6MLrud2HGx0mB3eQw==",
      "requires": {
        "@graphql-typed-document-node/core": "^3.0.0",
        "@types/zen-observable": "^0.8.0",
        "@wry/context": "^0.5.2",
        "@wry/equality": "^0.3.0",
        "fast-json-stable-stringify": "^2.0.0",
        "graphql-tag": "^2.12.0",
        "hoist-non-react-statics": "^3.3.2",
        "optimism": "^0.14.0",
        "prop-types": "^15.7.2",
        "symbol-observable": "^2.0.0",
        "ts-invariant": "^0.6.2",
        "tslib": "^1.10.0",
        "zen-observable": "^0.8.14"
      },
      "dependencies": {
        "ts-invariant": {
          "version": "0.6.2",
          "resolved": "https://registry.npmjs.org/ts-invariant/-/ts-invariant-0.6.2.tgz",
          "integrity": "sha512-hsVurayufl1gXg8CHtgZkB7X0KtA3TrI3xcJ9xkRr8FeJHnM/TIEQkgBq9XkpduyBWWUdlRIR9xWf4Lxq3LJTg==",
          "requires": {
            "@types/ungap__global-this": "^0.3.1",
            "@ungap/global-this": "^0.4.2",
            "tslib": "^1.9.3"
          }
        }
      }
    }
}

@jrebmann
Copy link
Author

Thank you very much! Everything is now working as desired.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants