Next.js Discord

Discord Forum

Mapping import statements with duplicate directory segments

Unanswered
Spinge Bib Sqorpnts posted this in #help-forum
Open in Discord
Is there a way to map an import path like
import foo from 'path/to/foo/foo';

to
import foo from 'path/to/foo';

While keeping the same file & folder structure and functionality?

5 Replies

Westphalian Dachsbracke
If you add a index.ts file inside the foo folder, and then in that index.ts file you have following code

export * from './foo'

Then yes
That is a very common pattern and would solve you issue i belive 🙂
@Westphalian Dachsbracke If you add a index.ts file inside the foo folder, and then in that index.ts file you have following code tsx export * from './foo' Then yes
Is there a way to do this using webpack/nextconfig without having to rename the file inside the folder to index.*?
@Spinge Bib Sqorpnts Is there a way to do this using webpack/nextconfig without having to rename the file inside the folder to `index.*`?
Westphalian Dachsbracke
Not sure, but i do not think so. I have never seen that and also feels like something that would not be recommended tbh