https://i.sstatic.net/kLB0S.png
The directory structure above shows how my react app 'MyProject' is organized.
Using this structure, I successfully utilize the Layout
component in Main.jsx
(located at src/Main.jsx
) by :
import Layout from './layout'
(the layout
folder contains an index.js
file that exports the Layout component by default)
Additionally, I am able to use the Content component in ErrorBoundary.js
(located at src/ErrorBoundary.js
) by:
import Content from '../../layout/content/Content'
(the content
folder has an index.js
file inside it that exports the Content component by default)
However, when attempting to run webpack, I encounter the following errors:
Module not found: Error: Can't resolve './layout/content/Content' in '/home/user/myProject/src'
// Errors related to alias configurations and path resolutions
I tried using aliases as per the webpack documentation, but no success:
alias: {
Layout: path.resolve(__dirname, "/src/layout/Layout"),
Content: path.resolve(__dirname, "/src/layout/content/Content")
}
This is my current webpack configuration:
// Webpack config details...
Am I correctly implementing aliases or is there another approach to resolving this error?
Further information on utilizing aliases can be found in a table under resolve.alias in the webpack documentation, but I'm unsure how to apply it to my specific situation.