Feature(s) impacted
Build typescript to javascript & run it
Observed behavior
When running JS app after build using tsc
it fails with error
Error: Collection 'Address' not found. List of available collections:
while when running with ts-node
it runs fine
Expected behavior
No failure on JS run
Failure Logs
The full error stacktrace:
.../forest_ts/node_modules/@forestadmin/datasource-customizer/dist/decorators/composite-datasource.js:22
throw new Error(`Collection '${name}' not found. List of available collections: ${this.collections
^
Error: Collection 'Address' not found. List of available collections:
at CompositeDatasource.getCollection (.../forest_ts/node_modules/@forestadmin/datasource-customizer/dist/decorators/composite-datasource.js:22:15)
at DataSourceDecorator.getCollection (.../forest_ts/node_modules/@forestadmin/datasource-toolkit/dist/src/decorators/datasource-decorator.js:16:49)
at DataSourceDecorator.getCollection (.../forest_ts/node_modules/@forestadmin/datasource-toolkit/dist/src/decorators/datasource-decorator.js:16:49)
at DataSourceDecorator.getCollection (.../forest_ts/node_modules/@forestadmin/datasource-toolkit/dist/src/decorators/datasource-decorator.js:16:49)
at .../forest_ts/node_modules/@forestadmin/datasource-customizer/dist/collection-customizer.js:29:76
at DecoratorsStack.applyQueuedCustomizations (.../forest_ts/node_modules/@forestadmin/datasource-customizer/dist/decorators/decorators-stack.js:75:47)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async DataSourceCustomizer.getDataSource (.../forest_ts/node_modules/@forestadmin/datasource-customizer/dist/datasource-customizer.js:126:9)
at async .../forest_ts/node_modules/@forestadmin/datasource-customizer/dist/datasource-customizer.js:46:30
at async DecoratorsStack.applyQueuedCustomizations (.../forest_ts/node_modules/@forestadmin/datasource-customizer/dist/decorators/decorators-stack.js:75:13)
Node.js v20.9.0
Context
We’ve done re-developped our current forestadmin setup using the new typescript engine in parallel to our current JS setup, we’re now preparing to deploy it on our target envs. Typescript to javascript build works fine but running the javascript built version fails with no collections found.
- Project name: UC Typescript
- Team name: -
- Environment name: Development
- Node version: 20.9.0
- Agent (forest package) name & version:
"@forestadmin/agent": "^1.28.3",
"@forestadmin/datasource-customizer": "^1.28.2",
"@forestadmin/datasource-sequelize": "^1.5.14",
"@forestadmin/datasource-sql": "^1.7.26",
- Database type: postgres
"sequelize": "^6.32.1",
"sequelize-typescript": "^2.1.5",
- Recent changes made on your end if any: -
- tsconfig.json:
{
"extends": "@tsconfig/recommended/tsconfig.json",
"compilerOptions": {
"outDir": "./build/",
"types": [
"jest",
"node"
],
"typeRoots": [
"node_modules/@types",
"src/@types"
],
"noImplicitAny": true,
"moduleResolution": "node",
"target": "es2020",
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"skipLibCheck": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
},
// ...
}
- build command:
tsc --project tsconfig.json
- run command:
node ./build/src/index.js
- uncompiled run command:
npx ts-node ./src/index.ts
- collections declaration:
const sequelize = new Sequelize(process.env.DATABASE_URL ?? '', dbOptions)
sequelize.addModels([join(__dirname, '../collections/*/model.ts')])
export const forestAgent = createAgent({
authSecret: process.env.FOREST_AUTH_SECRET ?? '',
envSecret: process.env.FOREST_ENV_SECRET ?? '',
isProduction: process.env.NODE_ENV === 'production',
typingsPath: './typings.ts',
}).addDataSource(
createSequelizeDataSource(sequelize),
)