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

TypeScript prompts an error when importing @vueuse/motion #118

Closed
lxxorz opened this issue May 9, 2023 · 12 comments
Closed

TypeScript prompts an error when importing @vueuse/motion #118

lxxorz opened this issue May 9, 2023 · 12 comments

Comments

@lxxorz
Copy link

lxxorz commented May 9, 2023

TypeScript prompts an error when importing @vueuse/motion

image

Steps to Reproduce:

Run

  1. pnpm create vite to create a new Vite project.
    Choose Vue + TypeScript as the project template.
  2. pnpm add @vueuse/core @vueuse/motion

Expected Behavior:

The packages @vueuse/core and @vueuse/motion should be installed and imported without any TypeScript errors.

Actual Behavior:

When importing @vueuse/motion, TypeScript provides the following error message:

Could not find a declaration file for module '@vueuse/motion'. '/home/user/test/node_modules/.pnpm/@vueuse+motion@2.0.0-beta.27_vue@3.2.47/node_modules/@vueuse/motion/dist/index.mjs' implicitly has an 'any' type.
There are types at '/home/user/test/node_modules/@vueuse/motion/dist/index.d.ts', but this result could not be resolved when respecting package.json "exports". The '@vueuse/motion' library may need to update its package.json or typings.ts(7016)

Additional Information:
package.json

{
  "dependencies": {
    "@vueuse/core": "^10.1.2",
    "@vueuse/motion": "2.0.0-beta.27",
    "vue": "^3.2.47"
  },
  "devDependencies": {
    "@vitejs/plugin-vue": "^4.1.0",
    "typescript": "^5.0.2",
    "vite": "^4.3.2",
    "vue-tsc": "^1.4.2"
  }
}
@ktranish
Copy link

I get the same result when trying to incorporate this package into my typescript vue build

@init-center
Copy link

same error

@Gabrodriguez8i
Copy link

same error...

@MaxTechnics
Copy link
Contributor

MaxTechnics commented Jun 13, 2023

This only seems to happen on ts 5 builds
Edit: TS4.9 seems to also be affected by this due to the new way it resolves typing imports

MaxTechnics added a commit to MaxTechnics/motion that referenced this issue Jun 13, 2023
This is related to vueuse#118

Turns out that the typings field is no longer being used when an exports field is defined.

source: https://stackoverflow.com/questions/76211877/the-xxxx-library-may-need-to-update-its-package-json-or-typings-ts
@MIN202299
Copy link

To solve this problem, modify the tsconfig.json file

tsconfig.json

@ramonakira
Copy link

ramonakira commented Aug 15, 2023

I tried the above fix but I am still getting the aforementioned error.

src/main.ts:1:30 - error TS7016: Could not find a declaration file for module '@vueuse/motion'. '/*/node_modules/@vueuse/motion/dist/index.mjs' implicitly has an 'any' type.
  There are types at '/*/node_modules/@vueuse/motion/dist/index.d.ts', but this result could not be resolved when respecting package.json "exports". The '@vueuse/motion' library may need to update its package.json or typings.

1 import { MotionPlugin } from '@vueuse/motion'
                               ~~~~~~~~~~~~~~~~


Found 1 error in src/main.ts:1

ERROR: "type-check" exited with 2.

@marsidev
Copy link

Same here.

@afrijaldz
Copy link

afrijaldz commented Nov 3, 2023

I solved this issue by changing the tsconfig.json with this

{
  "compilerOptions": {
    "target": "esnext",
    "module": "esnext",
    "lib": ["dom", "esnext"],
    "strict": true,
    "noImplicitAny": false,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "incremental": true,
    "moduleResolution": "node",
    "forceConsistentCasingInFileNames": true
  },
  "exclude": ["node_modules", "dist"]
}


@byStrange
Copy link

setting moduleResolution to node woked for me
"moduleResolution": "node"

@MoRanYue
Copy link

MoRanYue commented Feb 20, 2024

that configuration doesnt work on my project, i dont know why, i still get that error

@BobbieGoede
Copy link
Collaborator

I'm unable to reproduce this issue by following your reproduction steps using the latest release v2.1.0, so I think this issue has been resolved and can be closed.

@MaxTechnics
Copy link
Contributor

Can confirm that this release fixed the issue

@Tahul Tahul closed this as completed Feb 23, 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