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

Fix type definitions with moduleResolutions nodenext #2213

Open
ZachHaber opened this issue Feb 22, 2023 · 3 comments
Open

Fix type definitions with moduleResolutions nodenext #2213

ZachHaber opened this issue Feb 22, 2023 · 3 comments

Comments

@ZachHaber
Copy link

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch [email protected] for the project I'm working on.

Typescript with nodenext resolution ignores the "typings" property completely when "exports" is specified, which causes typescript to complain that it can't find any type definitions for this package.

microsoft/TypeScript#49160 (comment)

This should work fine on both v3 and v4, since both have the same issue with typescript and the exports object.

Here is the diff that solved my problem:

diff --git a/node_modules/vuex/package.json b/node_modules/vuex/package.json
index e8a851e..4cd1fce 100644
--- a/node_modules/vuex/package.json
+++ b/node_modules/vuex/package.json
@@ -7,7 +7,8 @@
     ".": {
       "module": "./dist/vuex.esm.js",
       "require": "./dist/vuex.common.js",
-      "import": "./dist/vuex.mjs"
+      "import": "./dist/vuex.mjs",
+      "types": "./types/index.d.ts"
     },
     "./": "./"
   },

This issue body was partially generated by patch-package.

@trim21
Copy link

trim21 commented Apr 26, 2023

last fix commit is 2 years , I'm wondering is this package still maintained...

@masaha03
Copy link

My workaround for the vuex type definition error:

declare module "vuex" {
  export * from "vuex/types/index.d.ts";
  export * from "vuex/types/helpers.d.ts";
  export * from "vuex/types/logger.d.ts";
  export * from "vuex/types/vue.d.ts";
}

Save the above code under an appropriate directory with a name like vuex.d.ts. This should allow TypeScript to correctly recognize the vuex module.

@stouch
Copy link

stouch commented Dec 19, 2023

Changing the vuex package.json with :

{
  "name": "vuex",
  "version": "4.0.2",
...
  "exports": {
    ".": {
      "module": "./dist/vuex.esm-bundler.js",
      "require": "./dist/vuex.cjs.js",
      "import": {
         "default": "./dist/vuex.mjs", 
         "types": [
            "./types/index.d.ts",
            "./types/helpers.d.ts",
            "./types/logger.d.ts",
            "./types/vue.d.ts"
          ]
      }
    },
  },
...

fixes the issue

xymopen added a commit to xymopen/CuckooPlus that referenced this issue Oct 30, 2024
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

4 participants