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

Types are not being detected in v2 #63

Closed
SimeonC opened this issue Jul 27, 2023 · 6 comments
Closed

Types are not being detected in v2 #63

SimeonC opened this issue Jul 27, 2023 · 6 comments

Comments

@SimeonC
Copy link

SimeonC commented Jul 27, 2023

It looks like in v2 the exports field in the package.json is missing meaning that not all configurations for tsconfig.json are supported.

For example if you open up the react-express stackblitz, it compiles fine but vavite (and others admittedly) have red squiggly lines under them as the types cannot be found.

Changing node_modules/vavite/package.json to be the following worked for me locally; (took inspiration from the package definition of vite but vavite needs to be different for some reason.

  "type": "module",
  "module": "./dist/index.js",
  "types": "./dist/index.d.ts",
  "files": [
    "dist",
    "*.d.ts",
    "node-loader.mjs",
    "suppress-loader-warnings.cjs"
  ],
  "exports": {
    ".": {
      "import": "./dist/index.js",
      "require": "./dist/index.cjs",
      "types": "./dist/index.d.ts"
    },

My tsconfig.json relevant settings are;

    "module": "ES2020",
    "target": "ESNext",
    "moduleResolution": "Bundler",
@SimeonC
Copy link
Author

SimeonC commented Jul 27, 2023

Sorry about this looks like it is working correctly. Turns out I just didn't have it included in my tsconfig.json so it silently failed to load for some unknown reason. Typescript configuration is hard 😂

@SimeonC SimeonC closed this as completed Jul 27, 2023
@cyco130
Copy link
Owner

cyco130 commented Jul 27, 2023

Typescript configuration is hard 😂

Tell me about it 😅

I prefer the typesVersions trick which I find cleaner than manually specifying each type definition file.

Just double-checked in any case and Are the Types Wrong suggests that everything's fine:

  • vavite/vite-dev-server and vavite/http-dev-server are not meant to be consumed from CommonJS (they're virtual modules meant to be consumed from a Vite app), so the failures for "node16 (from CJS)" are OK.
  • vavite/node-loader and vavite/suppress-loader-warnings don't need types, so those failures are also OK.

publint just improved its type resolution error detection, so hopefully we'll have more confidence in our types from now on.

@SimeonC
Copy link
Author

SimeonC commented Jul 27, 2023

Nice, I hadn't heard of publint before. I'll probably try use that on my projects too.

Thanks for taking the time to reply, that error caused by not including the config file had me frustrated for a day before opening this. Annoyingly enough VSCode will happily tell you TS is running on the file, but give cryptic errors until it's included properly.

@jensbodal
Copy link
Contributor

Sorry about this looks like it is working correctly. Turns out I just didn't have it included in my tsconfig.json so it silently failed to load for some unknown reason. Typescript configuration is hard 😂

What was not included in your tsconfig.json?

@SimeonC
Copy link
Author

SimeonC commented Aug 28, 2023

Sorry about this looks like it is working correctly. Turns out I just didn't have it included in my tsconfig.json so it silently failed to load for some unknown reason. Typescript configuration is hard 😂

What was not included in your tsconfig.json?

The vite.config.ts file, had included subfolders but not root level ts files

@jensbodal
Copy link
Contributor

Ah thanks just arrived at the same conclusion :)

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

3 participants