0

After trying to import my function, I've got an error:

Module not found: Can't resolve 'fetchProducts' in 'C:\Users\lesha\Desktop\blog\src\components\HomePage'

Screen of my hierarchy:

enter image description here

I don't know where the problem is

HomePage.jsx

import React, { Component } from "react";
import "./HomePage.css";
import { connect } from "react-redux";
import { bindActionCreators } from "redux";
import fetchProductsAction from "fetchProducts";
import { fetchProducts } from "../fetchMovies/fetchMovies.js";
class HomePage extends Component {
  componentDidMount() {
    fetchProducts();
  }

  render() {
    return <div>asd</div>;
  }
}

const mapStateToProps = state => {
  return {};
};
const mapDispatchToProps = dispatch =>
  bindActionCreators(
    {
      fetchProducts: fetchProductsAction
    },
    dispatch
  );

export default connect(
  mapStateToProps,
  mapDispatchToProps
)(HomePage);

fetchMovies.js

import {
  fetchProductsPending,
  fetchProductsSuccess,
  fetchProductsError
} from "../../actions/index";

export function fetchProducts() {
  return dispatch => {
    dispatch(fetchProductsPending());
    fetch(
      "https://api.themoviedb.org/3/movie/top_rated?api_key=b05433b24b52d30bb0b22ecfd4f86001&language=en-US&page=1"
    )
      .then(res => res.json())
      .then(res => {
        if (res.error) {
          throw res.error;
        }
        dispatch(fetchProductsSuccess(res.products));
        console.log(res.products);
        return res.products;
      })
      .catch(error => {
        dispatch(fetchProductsError(error));
      });
  };
}

Heretic Monkey
  • 11,687
  • 7
  • 53
  • 122
lesha105
  • 3
  • 2

2 Answers2

0

It's this line:

import fetchProductsAction from "fetchProducts";

Node attempts to load a module called 'fetchProducts' which probably can't be found.

You may want to find out where something called fetchProducts is declared and load it from there.

Jb31
  • 1,381
  • 1
  • 10
  • 19
0
  1. create .env file to your root folder

  2. Place NODE_PATH=./src into your .env file

  3. Now Try, import { fetchProducts } from "../fetchMovies/fetchMovies.js";

Mahesh Joshi
  • 608
  • 8
  • 9