babel-plugin-module-resolver
babel-plugin-module-resolver copied to clipboard
Alias syntax for multi-level paths?
Hi.
So I have the following structure: src/lessons/01/Lesson01.tsx
I've setup the following in my babel.config.js
[
'module-resolver',
{
root: './src',
alias: {
lessons: ([, subDir]) => {
return `./src/lessons${subDir}`
},
},
},
],
The following statement resolved correctly as I have an index.ts file in the lessons directory:
import Lesson1 from 'lessons'.
However, if I try to access the following import Lesson1 from 'lessons/01/Lesson1' I get the following error message: Unable to resolve "./lessons/index.ts/01/Lesson01" from "src/index.tsx"
So it seems as though the file name of the file referencing the alias is being added to the path structure: ./lessons/index.ts/01/Lesson01.
Could someone enlighten me on how to make this work please? Thanks in advance.