bluwy / create-vite-extra

Extra Vite templates
MIT License
353 stars 53 forks source link

type errors with `deno-react` + `Typescript` #32

Open scarf005 opened 1 year ago

scarf005 commented 1 year ago

Issue

image JSX element implicitly has type 'any' because no interface 'JSX.IntrinsicElements' exists. errors are popping OOTB.

this may be related to https://github.com/denoland/deno/issues/9425.

How to reproduce

  1. follow the installation steps.
    
    $ deno run --allow-read --allow-write --allow-env npm:create-vite-extra@latest
    ✔ Project name: … vite-project
    ✔ Select a template: › deno-react
    ✔ Select a variant: › TypeScript

Scaffolding project in /home/scarf/repo/cata/vite-project...

Done. Now run:

cd vite-project deno task dev



2. enable deno for the workspace.
![image](https://github.com/bluwy/create-vite-extra/assets/54838975/52b3ddb0-205b-455d-ad3c-374369cfff33)

## System Information

ubuntu 23.04
vscode 1.78.1, with deno extension v3.17.0
bluwy commented 1 year ago

There's also a similar issue open in Vite recently without Deno: https://github.com/vitejs/vite/issues/13129. Not sure if it's related. There's also this Deno issue which seems to be the same: https://github.com/denoland/deno/issues/16653. The solution (https://github.com/denoland/deno/issues/16653#issuecomment-1383657630) worked a bit but there's still lingering TS errors.

cc @bartlomieju

rpasechnikov commented 1 year ago

Hi!

That sounds similar to an issue I had a few days ago. Updating moduleResolution to node (maybe others too) fixed it for me. Updating VS Code was ultimately the solution, which allowed me to roll back changes to moduleResolution back to bundler.

https://github.com/vitejs/vite/issues/13129

bartlomieju commented 1 year ago

Thanks for the ping, I'll try to investigate this problem.

hastebrot commented 1 year ago

as a work-around I've disabled the path to my vite application (running on deno runtime) for deno.enablePaths in .vscode/settings.json.

I've created a deno-react application using npm:create-vite-extra

❯ deno run --allow-read --allow-write --allow-env npm:create-vite-extra@latest

After I renamed src/main.jsx to src/main.tsx I had to change vite.config.mjs to include npm:@types/react

import "npm:react@18.2.0";
import "npm:react-dom@18.2.0";
import "npm:react-router-dom@6.14.1";

try {
  await import("npm:@types/react");
  await import("npm:@types/react-dom");
} catch (ignore) {}

the imports need to be wrapped into a try-catch because vite/deno complain about import problems, but the important thing is that ./node_modules/@types/react exists for the normal vscode typescript LSP.

Screenshot 2023-07-13 at 16 00 36

tsconfig.json:

{
  "compilerOptions": {
    "moduleResolution": "Bundler",
    "module": "ESNext",
    "target": "ES2022",
    "types": ["node"],
    "lib": ["esnext", "dom"],
    "jsx": "react",
    "allowImportingTsExtensions": true,
    "allowSyntheticDefaultImports": true,
    "noEmit": true
  }
}
Andonvr commented 1 month ago

I have the same issue, and @hastebrot 's solution didn't work for me. Can someone link me a working example?

RioChndr commented 3 hours ago

I had same problem, the problem is we had to include the types of react into deno runtime, I write the solution on my blog. tldr; I use esm.sh instead npm.