Should I be able to use absolute path imports?
See original GitHub issueHi there,
I’m wondering if I’m supposed to be able to do something like
import ComponentWhatever from 'src/components/ComponentWhatever'
instead of one of these:
import ComponentWhatever from '@/components/ComponentWhatever'
import ComponentWhatever from '../components/ComponentWhatever'
I found the @
alias, but I’m not sure if absolute paths work out-of-the-box. I’m running into issues with my vue-cli-webpack project + Jest, and I think it’s because Jest is not translating the @
alias so I’d like to avoid it and just use the absolute path (if possible).
thanks!
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Why and How to Use Absolute Imports in React
Using absolute imports to better organize your React project is a great way. Relative imports are hard to follow and break during ...
Read more >Use Absolute Paths with React - Better Programming
In this article, I will walk you through adding support for absolute paths to your project using Webpack.
Read more >Absolute imports and module path aliases are a game changer!
So we can make use of paths to declare module aliases. The configuration would look something like this: The import after configuring module...
Read more >Importing with Absolute Paths in JavaScript/TypeScript using ...
How to use absolute paths in JavaScript and TypeScript to improve your import statements, using the right webpack configuration.
Read more >Absolute vs Relative Imports in Python
An absolute import specifies the resource to be imported using its full path from the project's root folder. Syntax and Practical Examples. Let's...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Well, looks like I fixed my issue with Jest, just missed this regex pattern in my
ModuleNameMapper
:I still don’t get why I can’t just use
src/components/Component/
but since the@
alias is working…@nickmessing finally! Now I understand, I was adding both the
module.exports
line and alsosrc/
to every import statement. Thanks!Then I added
to the ModuleNameMapper object from my Jest config and
components/MyComponent
worked fine both in dev and test environments.Kudos to you! 🎉