-
Notifications
You must be signed in to change notification settings - Fork 133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeError: Cannot read property 'name' of undefined #154
Comments
Hi! Can you share how are you running the seeder? Just running BTW, I updated your issue to use markdown, more readable 👍 |
@alfaben12 We just had this same error. It boiled down to bad paths passed to the module.exports = {
...
seeds: ['src/seeds/**/*{.ts,.js}'],
factories: ['src/factories/**/*{.ts,.js'], // Note the missing closing "}"
} Further Explanation: Here export const factory: Factory = <Entity, Context>(entity: ObjectType<Entity>) => (context?: Context) => {
// ... entityFactory is undefined vvvvv
return new EntityFactory<Entity, Context>(name, entity, entityFactoryObject.factory, context)
} It gets defined when define is called somewhere in your factories code. If the Hope that helps |
Please @alfaben12, could you check what @harveysanders said? If that fixes your problem, I could try to do something with path validation (Maybe print files loaded with verbose flag?) |
@alfaben12 I'm sorry I think I may have jumped the gun with your error. Our error was "Cannot read property 'factory' of undefined". I'm not sure it's related to your error. Looking at your stack trace, I see your error is due to undefined seeds so it's possible your problem is similar.
Check your seeds path in your ormconfig file. Try throwing in a log in one of your seed files to ensure they're being loaded and executed. |
@harveysanders thank you for reference, my ormconfig is wrong that's why maybe that's why we get the same error ormconfig.json (Before) "entities": ["dist/**/*.entity{.ts,.js}"],
"seeds": ["dist/**/*.factory{.ts,.js}"],
"factories": ["dist/**/*.seed{.ts,.js}"], ormconfig.json (After) "entities": ["src/**/*.entity{.ts,.js}"],
"seeds": ["src/**/seeds/*{.ts,.js}"],
"factories": ["src/**/factories/*{.ts,.js}"], package.json (Before) "seed:config": "ts-node ./node_modules/typeorm-seeding/dist/cli.js config",
"seed:run": "ts-node ./node_modules/typeorm-seeding/dist/cli.js seed" package.json (After) "seed:config": "npm run build && ts-node -r tsconfig-paths/register ./node_modules/typeorm-seeding/dist/cli.js config",
"seed:run": "npm run build && ts-node -r tsconfig-paths/register ./node_modules/typeorm-seeding/dist/cli.js seed" Conclusion for ormconfig.json my bad is, I reverse for seed and factory and change entities from dist/ to src/ if you not change to src/ folder you will get error like this
Add -r tsconfig-paths/register in seed:config & seed:run again, if not added maybe the entity will not be found when run seed:run |
I'll check this with sample code, maybe docs could be updated with this info. |
# # |
Hi I'am already following instruction on docs but I got this error
user.factory.ts
And
create-user.seed.ts
The text was updated successfully, but these errors were encountered: