I would like to know how to import from the barrel file by referencing the directory and not the index file & extension. I don't want to use any .json file to get it.
In my case I have like 10 imports from that directory, and I would not like to see 10 lines of imports in the file that needs them, so I made an index.ts file to export these 10 modules or functions, and when trying to import it as:
import { foo1, foo2, foo3, foo4 } from '../foo';
I get the following error:
Unable to load a local module: "file:///home/iuser/project/src/foo". Please check the file path
It works by putting the file as follows:
import { foo1, foo2, foo3, foo4 } from '../foo/index.ts';
I will try to be clearer with the following example:
My models directory:
models
User.ts
Task.ts
Server.ts
Game.ts
Paris.ts
index.ts
index.ts
export * from 'User.ts';
export * from 'Task.ts';
export * from 'Server.ts';
export * from 'Game.ts';
export * from 'Paris.ts';
This is what I'm looking for: joinController.ts
import { User, Task, Server, Game, Paris } from '../models';
...
And what I don't want to do is reference the index.ts:
import { User, Task, Server, Game, Paris } from '../models/index.ts';
...
But honestly it doesn't seem clean code to me. I'm used to Node & ES6.