Error: Cannot find module (typeorm entity)
See original GitHub issueWhen I do seed:run in my NestJS app I get the following error:
� TypeORM Seeding v1.6.1
- Loading ormconfig
✔ ORM Config loaded
- Import Factories
✖ Could not import factories!
Error: Cannot find module 'src/users/user.entity'
Require stack:
- C:\Users\User\Development\example\example-api\src\database\factories\user.factory.ts
- C:\Users\User\Development\example\example-api\node_modules\typeorm-seeding\dist\utils\file.util.js
- C:\Users\User\Development\example\example-api\node_modules\typeorm-seeding\dist\commands\seed.command.js
- C:\Users\User\Development\example\example-api\node_modules\typeorm-seeding\dist\cli.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:797:15)
at Function.Module._load (internal/modules/cjs/loader.js:690:27)
at Module.require (internal/modules/cjs/loader.js:852:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object.<anonymous> (C:\Users\User\Development\example\example-api\src\database\factories\user.factory.ts:3:1)
at Module._compile (internal/modules/cjs/loader.js:959:30)
at Module.m._compile (C:\Users\User\Development\example\example-api\node_modules\ts-node\src\index.ts:858:23)
at Module._extensions..js (internal/modules/cjs/loader.js:995:10)
at Object.require.extensions.<computed> [as .ts] (C:\Users\User\Development\example\example-api\node_modules\ts-node\src\index.ts:861:12)
at Module.load (internal/modules/cjs/loader.js:815:32) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'C:\\Users\\User\\Development\\example\\example-api\\src\\database\\factories\\user.factory.ts',
'C:\\Users\\User\\Development\\example\\example-api\\node_modules\\typeorm-seeding\\dist\\utils\\file.util.js',
'C:\\Users\\User\\Development\\example\\example-api\\node_modules\\typeorm-seeding\\dist\\commands\\seed.command.js',
'C:\\Users\\User\\Development\\example\\example-api\\node_modules\\typeorm-seeding\\dist\\cli.js'
]
}
This is my seed:config:
� TypeORM Seeding v1.6.1
{
type: 'postgres',
host: 'localhost',
port: 5432,
username: 'example',
password: 'example',
database: 'example',
entities: [ 'dist/**/*.entity{.ts,.js}' ],
migrations: [ 'migration/*.js' ],
cli: { migrationsDir: 'migration' },
synchronize: true,
factories: [ 'src/database/factories/**/*{.ts,.js}' ],
seeds: [ 'src/database/seeds/**/*{.ts,.js}' ]
}
TypeORM is working fine with my app, but not this seeding package.
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (3 by maintainers)
Top Results From Across the Web
TypeOrm migration - Error: Cannot find module - Stack Overflow
Now I'm getting the error: RepositoryNotFoundError: No repository for "permissions" was found. Looks like this entity is not registered in ...
Read more >typeorm - npm
TypeORM is an ORM that can run in NodeJS, Browser, Cordova, PhoneGap, Ionic, React Native, NativeScript, Expo, and Electron platforms and ...
Read more >cannot find module 'process' or its corresponding type ...
ts:1:92 - error TS2307: Cannot find module 'typeorm' or its corresponding type declarations. 1 import { Column, Entity, PrimaryGeneratedColumn, CreateDateColumn ...
Read more >TypeORM Cannot use import statement outside a module
Hi the error is on your ormconfig.json file. check where is your code searching for the entities, migrations, subscribers in a dev, test ......
Read more >typeorm/typeorm - Gitter
... data to the type of that entity, I get a type error that property: id is missing ... (function (exports, require, module,...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Would recommend to use
npm install --save-dev tsconfig-pathsand in the seeding commands add-r tsconfig-paths/register, ie:In the package.json
My config:
It solved my issue. I think using .js files is a terrible idea, as often the dist folder content is not immediatly updated and the files may accumulate in it if you update the file names, causing strange effects when launching the fixtures.
Hi xcymax, i’ve had this problem in the past. This happens because you’re using absolute paths. You should use relative paths in all your imports, so that when you run your code in prod mode, which would normally be something like
node dist/mainit all works correctly.Also, in my experience i could not get my typeorm configuration to work with both
.tsand.jsfiles. If the above solution doesn’t work, i recommend you use your configuration with only.jsfiles and use nest cli’s start command to start your project. This way, nest builds and executes your application straight with javascript, using the dist folder.