2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

「JSX element implicitly has type 'any' because no interface 'JSX.IntrinsicElements' exists.」の解決方法

2
Posted at

はじめに

HonoでJSXを使おうとしたところエラーが発生しました。

前提

tsconfig.jsonのcompilerOptionsには公式ドキュメント通りのjsxの設定をしています。

tsconfig.json
{
  "compilerOptions": {
    "target": "ESNext",
    "module": "NodeNext",
    "strict": true,
    "verbatimModuleSyntax": true,
    "skipLibCheck": true,
    "types": ["node"],
    "jsx": "react-jsx",
    "jsxImportSource": "hono/jsx",
    "rootDir": "./",
    "outDir": "./dist"
  },
  "exclude": ["node_modules"]
}

問題

JSX element implicitly has type 'any' because no interface 'JSX.IntrinsicElements' exists.

ディレクトリ構成

my-app/
├── drizzle.config.ts
├── package.json
├── pnpm-workspace.yaml
├── tsconfig.json
└── src/
	├── index.ts /apiのエンドポイント
	├── index.tsx /のエンドポイント(jsxを返す)
	└── db/
		└── schema.ts

原因

index.tsとindex.tsxが同じディレクトリに存在することが原因でした。

# 実行したコマンド
npx tsc --noEmit --listFilesOnly | grep -v node_modules

# 出力結果
/Users/workspace/my-app/drizzle.config.ts
/Users/workspace/my-app/src/db/schema.ts
/Users/workspace/my-app/src/index.ts

実行したコマンドは型チェックの対象のTypeScriptのファイルからnode_modules以外のファイルを出力するものです。
出力結果からindex.tsxは型チェックの対象になっていないことがわかります。つまり、tsconfig.jsonの内容を無視してエディタがエラーを出しているということです。

解決方法

ファイル名をindex.tsx → pages.tsxに変更

おわりに

compilerOptionsの設定は正しかったのですが、それがindex.tsxに反映されていませんでした。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?