sequelize-typescript: TypeError: Class constructor Model cannot be invoked without 'new'
I try to create new instance of my Model but have the following error:
throw er; // Unhandled 'error' event
^
TypeError: Class constructor Model cannot be invoked without 'new'
at new Student (/service/dist/app/student/student.model.js:58:125)
at Function.build (/service/node_modules/sequelize/lib/model.js:1976:12)
at Function._target.(anonymous function) [as build] (/service/node_modules/sequelize-typescript/lib/models/BaseModel.js:36:41)
at Function.create (/service/node_modules/sequelize/lib/model.js:2027:17)
at Function._target.(anonymous function) [as create] (/service/node_modules/sequelize-typescript/lib/models/BaseModel.js:36:41)
at /service/dist/app/metrics/action.js:66:69
at Array.forEach (<anonymous>)
at /service/dist/app/metrics/action.js:64:43
at /service/node_modules/mongoose/lib/model.js:4499:16
at process.nextTick (/service/node_modules/mongoose/lib/helpers/query/completeMany.js:35:39)
at _combinedTickCallback (internal/process/next_tick.js:132:7)
at process._tickCallback (internal/process/next_tick.js:181:9)`
Name of my model is Student. It’s a code:
User.find({}, (err, users) => {
if (err) throw new Error();
users.forEach((user) => {
if ((user as any).type === 2) {
Student.create({
uuid: user._id,
last_name: (user as any).lastName,
first_name: (user as any).firstName,
creation_date: (user as any).createdAt,
last_updated: (user as any).updatedAt,
});
}
});
I use typescript-sequelize 0.6.6. Also I try to create the same instance by using build
and new
. The results of this actions are the same
My tsconfig.json
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"removeComments": true,
"sourceMap": true,
"outDir": "app",
"rootDir": "src",
"strictNullChecks": true,
"noImplicitAny": true,
"jsx": "react",
"skipLibCheck": true,
"alwaysStrict": true,
"noImplicitReturns": true,
"sourceRoot": "src",
"allowJs": false,
"experimentalDecorators": true,
"mapRoot": "app",
"moduleResolution": "node",
"lib": ["dom", "es6", "es2015.promise", "es2016", "es2017", "es5"],
"typeRoots": ["node_modules/@types"],
"baseUrl": "./src",
"noUnusedLocals": true,
"noUnusedParameters": true,
"emitDecoratorMetadata": true
},
"exclude": [
"node_modules",
"app",
"**/*.test.ts",
"**/*.test.tsx"
],
"awesomeTypescriptLoaderOptions": {
"forkChecker": true,
"useWebpackText": true
},
"compileOnSave": true,
"buildOnSave": true,
"atom": {
"rewriteTsconfig": false
}
}
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 15 (5 by maintainers)
@acuntex I fix by setting
{ classTransformer: false }
in https://github.com/typestack/routing-controllers config.