How to set import shortcuts/aliases in create-react-app? From this:
import { Layout } from '../../Components/Layout'
to this:
import { Layout } from '@Components/Layout'
I have a webpack
4.42.0 version.
I don't have a webpack.config.js file in the root directory. I've tried to create one myself with this code inside:
const path = require('path')
module.exports = {
resolve: {
alias: {
'@': path.resolve(__dirname, 'src/'),
}
}
};
But it doesn't seem to work. I've seen the NODE_PATH=.
variant in .env
file. But I believe, it is deprecated - better not to use. And also, I have a posstcss.config.js
file. Because I've installed the TailwindCss and I import the CSS library there. I've tried to paste the same code there, but it also didn't work.
src/components
, then usingimport Game from 'components/Game'; - it didn't work. Gave me the error saying
Requests that should resolve in the current directory need to start with './'. Requests that start with a name are treated as module requests and resolve within module directories...` - perhaps this behaviour has changed. – Stalnaker