next.js: Module not found: Can't resolve webpack alias
Bug report
Describe the bug
I experience a problem with webpack aliases. They are not working since I’ve updated to Next v9. I get the following error:
Module not found: Can't resolve '~/components/nav' in '/Users/jerrygreen/projects/next-test/pages'
To Reproduce
I’ve made a repo with reproducible bug:
https://github.com/JerryGreen/next.js-issue8452
Steps to reproduce:
git clone https://github.com/JerryGreen/next.js-issue8452
cd next.js-issue8452
yarn
open http://localhost:3000
yarn dev
Expected behavior
The repo I’ve linked should work without bugs
Screenshots

System information
- OS: macos 10.14.5
- Version of Next.js: 9.0.4
Additional context
I think this might be related to this problem:
https://github.com/zeit/next.js/issues/8157
I am not sure but I’m experiencing this bug too, in my own project, since I’ve updated to Next v9. However, it’s not covered by my reproducible repo, nor by this issue. Just may be related.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 6
- Comments: 18 (14 by maintainers)
@timneutkens I also have a similar problem to @JerryGreen but I’m using typescript. I have tried to get alias working four the last couple hours but haven’t had much luck.
I’m getting
Module not found: Can't resolve '@modules/bootstrapApi' inpages/api.ts`. Alias doesn’t also work in the other pagesThe provided demo deploys to Now and runs locally for me just fine.
However, to be safe, the alias should be:
Closing this as there’s no Next.js bug – this is just standard webpack modification.
You’ll want to
resolve('./src'), notice the./part.