question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[bug] false-positive success when using named export on seeder file

See original GitHub issue

Basically, 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]]

https://github.com/w3tecch/typeorm-seeding/blob/4136b0e0f58a4ec13b17c717bd026043fbdf7ddd/src/importer.ts#L3-L7

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:open
  • Created 3 years ago
  • Comments:10

github_iconTop GitHub Comments

2reactions
jorgebodegacommented, Oct 11, 2021

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!

1reaction
jorgebodegacommented, Oct 11, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found