I am using a TypeScript project I made by myself, but I am having some issues with imports and exports.
I have a folder classes with each class having it's specific file that exports the class. I then have a file index.ts, which imports all the classes and exports them from one file for easier use in code.
Person.ts:
class Person {}
export default Person
index.ts:
import Person from "./Person"
export { Person }
app.ts:
import { Person } from "@classes
const person = new Person()
The issue is that the above code does not work and fires an error classes_1.Person is not a constructor
I am using alias paths configured in tsconfig.json as so:
"paths": {
"@classes": ["classes"],
"@interfaces": ["interfaces"],
"@enums": ["enums"],
"@const": ["const"]
}
I am not using the format that is shown in TS docs: "@classes/*": ["classes/*"] as that is not ideal for my use case.
I compile the code with npx tsc && npx tsc-alias
If I look into the transpiled .js code, the VSCode understands all imports, but if I launch the app with node ./dist/app.js, it does not work.
I had a circular dependency between the files. In index.ts I was importing multiple classes, which were dependent on each other in some way. I fixed it by moving the depending class to the top, so the import statement imports that class first.