Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Module not found: Can't resolve './components/player' in '.../score-board-app/src/components'

I use Create-React-App to build a small React application. The full code is stored in github

My file structure:

src
  components
    Players.js
    Player.js
App.css
App.js
index.css
index.js
...

App.js:

import React from 'react';
import './App.css';
import PropTypes from 'prop-types';// used to fix the error: 'PropTypes' is not defined
import Header from './components/Header';
import Players from './components/Players';

const App = (props) => (
  <div className="scoreboard">
    <Header title={props.title} />
    <Players />
  </div>
  );

App.propTypes = {
  title: PropTypes.string.isRequired
};


export default App;

Player.js:

import React from 'react';

const Player = (props) => (
  <div className="player">
    <div className="player-name">
      Jim Hoskins
    </div>
    <div className="player-score">
      <div className="counter">
        <button className="counter-action decrement"> - </button>
        <div className="counter-score">31</div>
        <button className="counter-action increment"> + </button>
      </div>
    </div>
  </div>
);

export default Player;

Players.js:

import React from 'react';
import Player from './components/Player';

const Players = () => (
  <div className="players">
    <div className="player">
      <div className="player-name">
        Jim Hoskins
      </div>
      <div className="player-score">
        <div className="counter">
          <button className="counter-action decrement"> - </button>
          <div className="counter-score">31</div>
          <button className="counter-action increment"> + </button>
        </div>
      </div>
    </div>
    <div className="player">
      <div className="player-name">
        Juan Li
      </div>
      <div className="player-score">
        <div className="counter">
          <button className="counter-action decrement"> - </button>
          <div className="counter-score">30</div>
          <button className="counter-action increment"> + </button>
        </div>
      </div>
    </div>
  </div>
)

export default Players;

And the line import Player from './components/Player'; leads to this error: enter image description here But if I put this line on top of App.js file, it doesn't report such compiling error. I really want to know what's the issue indeed with my code?

like image 588
juanli Avatar asked Dec 24 '22 08:12

juanli


1 Answers

Your file path is wrong. Player is in the same folder as Players, so you need to just say import Player from './Player'

like image 173
JSilv Avatar answered Jan 13 '23 20:01

JSilv