Closed chungchi300 closed 4 years ago
Not only when the path is absolute. Same error, when relative too.
@victorschinaider is it a problem comes from the version update of nestjs ? Should we run in a lower version of nestjs @kamilmysliwiec ?
This issue is completely unrelated to NestJS.
The TypeError: Right-hand side of 'instanceof'
error occurs when you try to call instanceof
with the undefined
value. This means, in your example (@chungchi300) Photo
class is represented as undefined
for some reason. Just stop using absolute paths (which are considered as bad practice either way) and avoid using barrel files (index.ts
) where your IDE can mess up with the imports order.
I can understand avoid using barrel files, but in the typescript-starter, there is a "baseUrl": "./"
in tsconfig.json
, does it mean that we can use absolute path?If I use relative path, how can I avoid relative path hell? https://medium.com/beqode/absolute-vs-relative-import-paths-nodejs-1e4efa65a7bb
{
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es2017",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./",
"incremental": true
},
"exclude": ["node_modules", "dist"]
}
@chungchi300 it seems that you just have an invalid jest
configuration. By setting this:
"moduleDirectories": [
"./",
"node_modules"
],
jest
is incorrectly mapping external modules to non-existing directories. Hence, all the functions/types/classes from the typeorm
library = undefined
. I have removed this (+ enabled allowJs
in the tsconfig.json
) since you use JS files and it works, got rid of absolute paths, and it works.
This issue is not specifically related to NestJS, but rather to the way how jest
resolves modules. You should report future issues like this one in the jest
repository.
Bug Report
Current behavior
Input Code
https://github.com/chungchi300/typescript-starter
Expected behavior
The test should run successfully
Possible Solution
Environment