I have really strange errors after update Node from 14 to 18.18.2 LTS.
I’m using NestJS in my backend and after mentioned update I noticed a lot of errors like:
/backend/src/common/entities/base.service.ts:40
@Inject() private fileService: FileService;
^
ReferenceError: file_service_1 is not defined
at BaseObjectManager (/backend/src/common/entities/base.service.ts:40:36)
at Object.<anonymous> (/backend/src/modules/object-manager/user/user.service.ts:26:64)
at Module._compile (node:internal/modules/cjs/loader:1256:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
at Module.load (node:internal/modules/cjs/loader:1119:32)
at Function.Module._load (node:internal/modules/cjs/loader:960:12)
at Module.require (node:internal/modules/cjs/loader:1143:19)
at require (node:internal/modules/cjs/helpers:119:18)
at Object.<anonymous> (/backend/src/modules/object-manager/user/user.controller.ts:11:1)
at Module._compile (node:internal/modules/cjs/loader:1256:14)
I can easily fix it with changing the absolute import path to relative one:
Example:
from
import { User } from 'src/modules/user/entities/user.entity';
to
import { User } from '../../../../user/entities/user.entity';
Ok, I know the solution but the problem here is that I have to change 1200 files… so it’s not possible to do it manually.
My tsconfig file:
{
"compilerOptions": {
"noEmit": false,
"module": "commonjs",
"declaration": true,
"target": "ES2021",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./",
"removeComments": true,
"emitDecoratorMetadata": true,
"strictNullChecks": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"incremental": true,
"preserveWatchOutput": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"jsx": "react"
},
"include": ["src/**/*.ts", "src/**/*.tsx"],
"exclude": ["node_modules/**", "dist/**"]
}
Have you any other solution?
I just highlight, that the mix of relative and absolute paths works properly with Node 14.
I tried a lot of solutions like change the Nest version, change the tsconfig file etc. but I didn’t find solution.
Thanks for help in advance!
2
Answers
I guess you could use typescript path aliases to map that
src/*
into./src/*
Try to use "ts-imports-fixer" that can help automate the process of updateing your import paths in the codebase.
But this a correct tsconfig.json path mapping:
import