-
Notifications
You must be signed in to change notification settings - Fork 0
Controller loading doesn't work in compiled apps #2
Comments
Temporary Workaround (NOW OLD, SEE BELOW)A temporary workaround is to check if the current file being executed is a For example: const TYPESCRIPT_ACTIVE = __filename.endsWith('ts');
const controllerFilesGlob = TYPESCRIPT_ACTIVE
? 'src/modules/**/*.controller.ts'
: 'dist/src/modules/**/*.controller.js'; // set glob to compiled files if running JS
const kangoJS = new KangoJS({
globalPrefix: "/api/v2",
controllerFilesGlob,
});
await kangoJS.boostrap(app); I'm calling this a "temporary" workaround as I'm hoping there will be a solution that doesn't involve extra code from a user's perspective |
A possible solution could be something like https://stackoverflow.com/a/59607836: join(__dirname, '**', '*.entity.{ts,js}') Using An example could look something like this: const kangoJS = new KangoJS({
globalPrefix: "/api/v2",
controllerFilesGlob: join(__dirname, 'src/modules/**/*.controller.{ts,js}'),
}); Initial testing suggest this approach works fine. |
If a solution like one of the two above is always going to be required to overcome this issue, I would rather keep this as something the user can choose to manage how they wish. |
TODO
|
Package Information: kangojs, all versions
Describe the bug
When passing a
controllerFilesGlob
to KangoJS it will be a glob of typescript files, for examplesrc/modules/**/*.controller.ts
.When the app is compiled to JS this reference stays the same and so the compiled app fails to import the controllers as Typescript files can't be imported into the compiled JS.
To Reproduce
Steps to reproduce the behaviour:
src/modules/**/*.controller.ts
).ts-node
this will work fine.In my application the error is as follows:
Expected behaviour
I'm unsure at the moment. Ideally the solution should not require any changes from a user perspective.
Can KangoJS somehow hook into the typescript build to change that string?
When loading could KangoJS use
tsconfig.json
to transform the path if it detects it's running with JS not TS?Additional context
This could just be a fundamental problem with typescript & builds. It will probably be a good idea to see if this is an
issue other frameworks or libraries have needed to solve.
The text was updated successfully, but these errors were encountered: