-
-
Notifications
You must be signed in to change notification settings - Fork 40
Description
Versions
- Node: v18.20.5
- OS: Ubuntu 24.04 noble
Reproduction
I am having entities in different directory which are using inheritance.
MasterEntity
: Located insidesrc/common/entity/master.entity.ts
BaseEntity
: Located insidesrc/common/entity/base.entity.ts
UserEntity
: Located insidesrc/user/entity/user.entity.ts
OtpEntity
: Located insidesrc/sms/entity/otp.entity.ts
I am importing the parent entity using the normal importing using the vscode.
for example:
import { BaseEntity } from 'src/common/entity/base.entity';
export class UserEntity extends BaseEntity<UserEntity> {
...
}
This type of importing the parent entity gives me Not Found error when I run the seed:run
Error: Cannot find module 'src/common/entity/base.entity'
code: 'MODULE_NOT_FOUND'
Additional Details
root@fa9931f4e061:/app# npm run seed:run create-permissions.seeder.ts
> backend@0.0.1 seed:run
> ts-node ./node_modules/typeorm-extension/bin/cli.cjs seed:run -r ./ -d src/config/typeorm-datasource.ts -n create-permissions.seeder.ts
ℹ DataSource Directory: /app/src/config 11:29:51 PM
ℹ DataSource Name: typeorm-datasource.ts 11:29:51 PM
ℹ Seed Name: create-permissions.seeder.ts 11:29:54 PM
typeorm-extension seed:run
Populate the database with an initial data set or generated data by a factory.
Options:
-h, --help Show help [boolean]
--preserveFilePaths This option indicates if file paths should be
preserved. [boolean] [default: false]
-r, --root Root directory of the project. [default: "/app"]
--tsconfig, --tc Name (or relative path incl. name) of the tsconfig
file. [default: "tsconfig.json"]
-d, --dataSource Name (or relative path incl. name) of the data-source
file. [default: "data-source"]
-n, --name Name (or relative path incl. name) of the seeder.
-v, --version Show version number [boolean]
Error: Cannot find module 'src/common/entity/base.entity'
Require stack:
- /app/src/sms/entity/otp.entity.ts
- /app/node_modules/typeorm/util/ImportUtils.js
- /app/node_modules/typeorm/connection/ConnectionOptionsReader.js
- /app/node_modules/typeorm/globals.js
- /app/node_modules/typeorm/index.js
- /app/node_modules/typeorm-extension/dist/index.cjs
- /app/node_modules/typeorm-extension/bin/cli.cjs
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1140:15)
at Function.Module._resolveFilename.sharedData.moduleResolveFilenameHook.installedValue [as _resolveFilename] (/app/node_modules/@cspotcode/source-map-support/source-map-support.js:811:30)
at Function.Module._load (node:internal/modules/cjs/loader:981:27)
at Module.require (node:internal/modules/cjs/loader:1231:19)
at require (node:internal/modules/helpers:177:18)
at Object.<anonymous> (/app/src/sms/entity/otp.entity.ts:1:1)
at Module._compile (node:internal/modules/cjs/loader:1364:14)
at Module.m._compile (/app/node_modules/ts-node/src/index.ts:1618:23)
at Module._extensions..js (node:internal/modules/cjs/loader:1422:10)
at Object.require.extensions.<computed> [as .ts] (/app/node_modules/ts-node/src/index.ts:1621:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/app/src/sms/entity/otp.entity.ts',
'/app/node_modules/typeorm/util/ImportUtils.js',
'/app/node_modules/typeorm/connection/ConnectionOptionsReader.js',
'/app/node_modules/typeorm/globals.js',
'/app/node_modules/typeorm/index.js',
'/app/node_modules/typeorm-extension/dist/index.cjs',
'/app/node_modules/typeorm-extension/bin/cli.cjs'
]
}
The only working solution that I found is to replace all the import path to a relative path which does not being supported by the vscode. By the way, I am coding using NestJS framework.
Thank you in advance for any help or suggestions.
Steps to reproduce
Just created an import without a relative path to your entities file and then try to run the seed:run command. You see the Not Found
error.
What is Expected?
Supporting the not relative path by providing the project root path. I already provided the -r
options but not working.
`"seed:run": "ts-node ./node_modules/typeorm-extension/bin/cli.cjs seed:run -r ./ -d src/config/typeorm-datasource.ts -n create-permissions.seeder.ts"
What is actually happening?
Not being able to report the import without relative path.
For example, the path should be change as bellow
import { BaseEntity } from 'src/common/entity/base.entity';
import { BaseEntity } from '../../common/entity/base.entity';