[bug] false-positive success when using named export on seeder file
See original GitHub issueBasically, when the seeder file has some export const foo = 'bar'-ish statement, the run method is not invoked and the output is this:
🌱 TypeORM Seeding v1.6.1
✔ ORM Config loaded
✔ Factories are imported
✔ Seeders are imported
⠋ Connecting to the databaseINFO: All classes found using provided glob pattern xxx
INFO: All classes found using provided glob pattern xxx
✔ Database connected
👍 Finished Seeding
I think that typeorm-seeding CLI should ignore these statements regardless of whether it is right or not to have them in a seeder file.
I’ve notice that this behavior is due to seedFileObject[keys[0]]
because this will return the foo variable instead of the seeder class. I’ve thought that return seedFileObject.default was enough but @hirsch88 already use this in the past with require (on 84df811)
Maybe this should work but I’m not sure:
export const importSeed = async (filePath: string): Promise<SeederConstructor> => {
const seedFileObject: { [key: string]: SeederConstructor } = await import(filePath)
return seedFileObject.default
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:10
Top Results From Across the Web
How to fix/disable seemingly erroneous "No named exports ...
I believe the report is a false positive because when I run the code, everything works fine and I can indeed import the...
Read more >Node.js now supports named imports from CommonJS ...
To try and answer that question I installed Node.js v14.13.0 and started messing around with named exports and CJS modules – here's what...
Read more >Module Exports vs. Export Default: Why Not Both?
In the ES6 module world, this rigs it up so you can both do import A from './a' and get the default export...
Read more >should not import the named export from default ... - You.com
"ERROR in ./src/App.js 32: 15-28 Should not import the named export 'navbar' (imported as 'navbar') from default-exporting module (only default export is ...
Read more >Export and Import - The Modern JavaScript Tutorial
We can also use as to import under different names. ... There may be only one export default per file. ... export class...
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
No results found
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

Yes, that could work temporary while we still work on this. I will keep this issue open to use it as a reference.
Thanks for your help!
For me mikro-orm seeding is a very good example on how to do this. But is unreleased yet.
I’m pretty sure we should create a project and start working on next version, maybe a 2.x version, because there will be breaking changes for sure.