Doesn't resolve with babel-plugin-module-resolver files in SFCs
See original GitHub issueA component that imports from an alias with babel-plugin-module-resolver
will fail to resolve in jest. Seems like it’s not resolving ./
as the babel cwd, but from the component location.
Example
.babelrc:
{
"plugins": [
["module-resolver", { "alias": { "@": "src/components" } } ]
]
}
src/components/A.vue:
<template>
<p>{{ text }}</p>
</template>
<script>
export default {
data() {
return {
text: 'hi'
}
}
};
</script>
src/components/B.vue:
<template>
<ComponentA />
</template>
<script>
import ComponentA from '@/A.vue';
export default {
components: { ComponentA }
};
</script>
Result:
● Test suite failed to run
Cannot find module './src/components/A.vue' from 'B.vue'
at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:191:17)
...
Issue Analytics
- State:
- Created 6 years ago
- Reactions:6
- Comments:8 (3 by maintainers)
Top Results From Across the Web
babel-plugin-module-resolver not working on .jsx files
The module-resolver is able to resolve paths on .ts files but when it comes to render the first Component (.jsx) it shows me...
Read more >babel-plugin-module-resolver - npm
A Babel plugin to add a new resolver for your modules when compiling your code using Babel. This plugin allows you to add...
Read more >can't resolve 'fs' webpack 5 | The AI Search Engine You Control
Module not found: Error: Can't resolve 'fs' with webpack ... The .js file's loader is very comprehensive that covers node, web, web worker,...
Read more >Vue Test Utils and Jest: how to write simple unit tests for Vue ...
That's where babel comes in. There's a plugin — babel-plugin-module-resolver — that resolves aliases in babel.
Read more >Why You Should Use Babel Resolvers | by Izaak Schroeder
doesn't really tell you where the import lives, other than it's far away. ... There is a babel plugin for doing custom module...
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 FreeTop 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
Top GitHub Comments
Can confirm this bug. I have a component, which import another one from different directory. Importing this component with @ alias results in:
Cannot find module './src/components/partials/B' from 'A.vue'
But when i change import path to relative path, eg.'../../components/partials/B'
it resolves correctly. I added moduleNameMapper to Jest and configure babel alias.Hi @eddyerburgh As we spoke before, today I started working on debugging this issue. So far I have found out that using alias in
.babelrc
file will result in jest to look for the module as ahastePackage
which results in the error. Without the alias nothing is being searched for as ahastePackage
.I am looking to find out what is a
hastePackage
injest
, I was wondering if you or someone else has any ideas on this?