Import Error looking for import inside of the wrong folder

Viewed 20

I'm getting an import error stating that the component I'm importing is not found but the complier is looking in the wrong folder. Users.js is inside of the feature folder and I'm trying to import FakeData.js that exist inside of the src folder. I have two periods in the import statement ('../FakeData.js') so that it looks outside of the features folder back inside of src but that is not what is happening here. I have worked around this issue by migrating to a new a new React.js App and by changing my folder structure so that everything exist inside of src/ with no other folders but I want make sure I understand the source of this error so that I can organize my components into folders in the future.

The error message, screenshot of my folder structure is below. I've also included the Users component where the import error occurs.

Thank you for your time!

Error Message:

Module not found: Error: Can't resolve '../FakeData.js' in 'C:\Users\nmaka\Documents\Code\javascript\sampleprojects\cruddredux\src\features'
ERROR in ./src/features/Users.js 4:0-42
Module not found: Error: Can't resolve '../FakeData.js' in 'C:\Users\nmaka\Documents\Code\javascript\sampleprojects\cruddredux\src\features'

enter image description here

import {createSlice} from '@reduxjs/toolkit';
import { UsersData } from '../FakeData.js';

export const userSlice = createSlice({
        name: 'users',
        initialState: {value: UsersData },
        reducers: {
            addUser: (state, action) => {
                // Write code for adding a user 
            }
        },
        
    }
);


export default userSlice.reducer; 
0 Answers
Related