Skip to content
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

Import in the middle breaks drizzle-orm exports #141

Open
Lms24 opened this issue Jul 15, 2024 · 5 comments
Open

Import in the middle breaks drizzle-orm exports #141

Lms24 opened this issue Jul 15, 2024 · 5 comments

Comments

@Lms24
Copy link

Lms24 commented Jul 15, 2024

Expected Behavior

Using import-in-the-middle works with imports from drizzle-orm as with other NPM packages

Actual Behavior

Registering the import-in-the-middle hook causes certain top-level exports from the drizzle-orm package to be missing.

This was originally reported as a bug in our Sentry JS SDK repo and I tracked it down to registering the IITM hook as the only thing needed to reproduce the error.

Steps to Reproduce the Problem

I created a minimal reproduction example in this repo: https://github.com/Lms24/iitm-bug-drizzle-or

  1. clone repo
  2. npm install
  3. run node index.js:
    • observe 112 exports from drizzle-orm console log
    • script terminates successfully
  4. run node --import instrument.mjs index.js
    • observe 85 exports form drizzle-orm console log (=> 27 exports missing)
    • script crashes when calling one of the missing functions (e.g. drizzle.or())

Specifications

@Lms24
Copy link
Author

Lms24 commented Jul 15, 2024

This is likely a duplicate of #139.

I'm gonna leave this open from my end until we can confirm that #140 fixes this issue as well. If it does, sorry for the duplicate! If you wanna close this before, please feel free!

@timfish
Copy link
Contributor

timfish commented Jul 15, 2024

This is not a duplicate of #139 because my current PR doesn't fix this.

@timfish
Copy link
Contributor

timfish commented Jul 15, 2024

Oh wow, so this issue is caused by the fact that we are finding a duplicate export named or. Duplicate named exports are usually not exported up through to the root of the module but they are in this case because they come from the same source file.

A simpler reproduction:
a.mjs

export const val = 1;

b.mjs

export * from './a.mjs';

c.mjs

export * from './a.mjs';
export * from './b.mjs';

When run in Node, c.mjs has a single export named val.
When running through import-in-the-middle there is no export.

We are not currently checking if duplicate named exports are from the same source file.

@BryceMehring
Copy link

Is this planned on getting fixed? Currently right now I'm importing the CJS build of drizzle-orm instead of the ESM version to avoid this issue.

@jsumners-nr
Copy link
Contributor

You are welcome to submit a PR with a fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants