LoginSignup
1
2

More than 3 years have passed since last update.

React+Typescriptプロジェクトでnpm install axiosをするとエラーが発生した時の対処法

Last updated at Posted at 2020-10-01

エラー内容

TypeScript error in /Users/<ユーザ名>/Public/workspace/todoapp/src/App.tsx(1,19):
Could not find a declaration file for module 'react'. '/Users/<ユーザ名>/Public/workspace/todoapp/node_modules/react/index.js' implicitly has an 'any' type.
If the 'react' package actually exposes this module, consider sending a pull request to amend 'https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/react` TS7016

App.tsx
  > 1 | import React from "react";
      |                   ^
    2 | import "./App.css";
    3 | import Api from "./components/Api";
    4 | 

対処法

npmではなくyarnでインストールすれば正しく動きます。

$yarn add axios 

最後に

なぜnpmでは動かないのか調べても理解できませんでした。
原因をご存知の方は是非教えてください。
編集リクエストをいただければ、原因を追記しようと思います。

1
2
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
1
2