0
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?

More than 1 year has passed since last update.

[vite] プロジェクトの立ち上げたら「Cannot find module '...' Did you mean to set the 'moduleResolution' option to 'node' ...」が出てきてしまう件について

Last updated at Posted at 2023-10-13

始めに

フロントエンドの勉強中にviteを使ってなんか作ってみよーと思ったのが、ことの発端です。
プロジェクトを立ち上げてファイルを開いてみるとタイトルにあるようなエラー(?)が出てきたので、
対処してみました。

結論

プロジェクトディレクトリ直下のtsconfig.jsontsconfig.node.jsonファイルを以下のように変更するだけ!

/* tsconfig.jsonファイルにて */

"moduleResolution": "node", /* ←変更 */
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",

……………

/* tsconfig.node.jsonファイルにて */

{
  "compilerOptions": {
    "composite": true,
    "skipLibCheck": true,
    "module": "ESNext",
    "moduleResolution": "node",  /* ←変更 */
    "allowSyntheticDefaultImports": true
  },
  "include": ["vite.config.ts"]
}

追記〜!

プロジェクト立ち上げ後に以下コマンドを打って必要なライブラリをインストールしてもいけた

$ yarn

まとめ

簡単ですが、とりあえずこのように記載することでエラー(?)文を出さなくすることはできました。
何か間違い等ありましたら、ご指摘お待ちしています。

0
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
0
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?