3
2

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 3 years have passed since last update.

【React】Module not found: Can't resolveの解決法

Last updated at Posted at 2021-05-23

症状

Reactでnpm startしたらコンパイルエラーが発生して、正常に動作しませんでした。 翻訳すると、「モジュールが見つかりません」となりました。

エラーの内容から推察するに、importが悪さしているようです。

エラー
Failed to compile.

./src/containers/hofa.jsx
Module not found: Can't resolve '../component' in 'C:\Users\environment\project\containers
Hoge.jsx
import React from "react";
import {fetchfuga} from "../apis/fygaApis";

export const Hoge = () => {
  fuga = fetchfuga()

  returnn(
      <Wrapper>
        {fuga}
      </Wrapper>
  )
}
fugaApis.js

export function fetchfuga =() = {
  return "Fuga";
}

解決策

import文を修正することで解決しました。 エラーに行数が出たりしないので、少してこずりました。 importするときに、VScodeの補完機能などでパスを指定すると、安全かなと思われます。
Hoge.jsx
import {fetchfuga} from "../apis/fugaApis";

参考

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?