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

tsc fails to resolve vavite #73

Closed
m4rw3r opened this issue Sep 16, 2023 · 2 comments
Closed

tsc fails to resolve vavite #73

m4rw3r opened this issue Sep 16, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@m4rw3r
Copy link

m4rw3r commented Sep 16, 2023

After bumping a vavite dev-dependency from 1.7.0 to 2.0.2 tsc --noEmit suddenly fails to resolve the *.d.ts file for imports of vavite:

> tsc --noEmit

vite.config.ts:2:20 - error TS2307: Cannot find module 'vavite' or its corresponding type declarations.

2 import vavite from "vavite";

vavite itself still successfully manages to build the project.

With tsc --noEmit --traceResolution it seems like it incorrectly attempts to load type-definitions from dist/dist/index.cjs.d.ts, instead of dist/index.d.ts:

======== Resolving module 'vavite' from '/testproject/vite.config.ts'. ========
Explicitly specified module resolution kind: 'Node10'.
'paths' option is specified, looking for a pattern to match module name 'vavite'.
Loading module 'vavite' from 'node_modules' folder, target file types: TypeScript, Declaration.
Searching all ancestor node_modules directories for preferred extensions: TypeScript, Declaration.
Found 'package.json' at '/testproject/node_modules/vavite/package.json'.
File '/testproject/node_modules/vavite.ts' does not exist.
File '/testproject/node_modules/vavite.tsx' does not exist.
File '/testproject/node_modules/vavite.d.ts' does not exist.
'package.json' has a 'typesVersions' field with version-specific path mappings.
'package.json' does not have a 'typings' field.
'package.json' does not have a 'types' field.
'package.json' has 'main' field './dist/index.cjs' that references '/testproject/node_modules/vavite/dist/index.cjs'.
'package.json' has a 'typesVersions' entry '*' that matches compiler version '5.2.2', looking for a pattern to match module name 'dist/index.cjs'.
Module name 'dist/index.cjs', matched pattern '*'.
Trying substitution 'dist/*.d.ts', candidate module location: 'dist/dist/index.cjs.d.ts'.
File '/testproject/node_modules/vavite/dist/dist/index.cjs.d.ts' does not exist.
Loading module as file / folder, candidate module location '/testproject/node_modules/vavite/dist/dist/index.cjs.d.ts', target file types: TypeScript, Declaration.
File name '/testproject/node_modules/vavite/dist/dist/index.cjs.d.ts' has a '.d.ts' extension - stripping it.
File '/testproject/node_modules/@types/vavite.d.ts' does not exist.
Directory '/node_modules' does not exist, skipping all lookups in it.
'paths' option is specified, looking for a pattern to match module name 'vavite'.
Loading module 'vavite' from 'node_modules' folder, target file types: JavaScript.
Searching all ancestor node_modules directories for fallback extensions: JavaScript.
File '/testproject/node_modules/vavite/package.json' exists according to earlier cached lookups.
File '/testproject/node_modules/vavite.js' does not exist.
File '/testproject/node_modules/vavite.jsx' does not exist.
'package.json' has 'main' field './dist/index.cjs' that references '/testproject/node_modules/vavite/dist/index.cjs'.
'package.json' has a 'typesVersions' entry '*' that matches compiler version '5.2.2', looking for a pattern to match module name 'dist/index.cjs'.
Module name 'dist/index.cjs', matched pattern '*'.
Trying substitution 'dist/*.d.ts', candidate module location: 'dist/dist/index.cjs.d.ts'.
File '/testproject/node_modules/vavite/dist/dist/index.cjs.d.ts' does not exist.
Loading module as file / folder, candidate module location '/testproject/node_modules/vavite/dist/dist/index.cjs.d.ts', target file types: JavaScript.
File name '/testproject/node_modules/vavite/dist/dist/index.cjs.d.ts' has a '.d.ts' extension - stripping it.
Directory '/node_modules' does not exist, skipping all lookups in it.
======== Module name 'vavite' was not resolved. ========

My guess is that the addition of the typesVersions in cf2574a is the culprit.

@cyco130 cyco130 added the bug Something isn't working label Sep 16, 2023
@cyco130
Copy link
Owner

cyco130 commented Sep 16, 2023

You're right, there's a bug with the way types are bundled.

If you're able to switch to moduleResolution: bundler in your tscofig.json, that would be the best workaround for now.

@cyco130
Copy link
Owner

cyco130 commented Sep 25, 2023

Solved in 3.0.0.

@cyco130 cyco130 closed this as completed Sep 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants