fix: Skip wrapping CJS modules which result in invalid identifiers#115
fix: Skip wrapping CJS modules which result in invalid identifiers#115timfish wants to merge 7 commits intonodejs:mainfrom
Conversation
…nvalid-indentifiers
jsumners-nr
left a comment
There was a problem hiding this comment.
If such modules are rare, how did the issue get exposed?
| "cjs-module-lexer": "^1.2.2", | ||
| "module-details-from-path": "^1.0.3" | ||
| "module-details-from-path": "^1.0.3", | ||
| "@babel/helper-validator-identifier": "^7.24.7" |
There was a problem hiding this comment.
We could vendor this code and it's around 13kB.
This package has 50m weekly downloads so there's a high chance it will already be in many users dependencies.
There was a problem hiding this comment.
This package has 50m weekly downloads so there's a high chance it will already be in many users dependencies.
Maybe. But I've never seen the package before this PR. I looked through it back when this PR was opened, and I remember getting the impression that it could be overkill. So I wanted an opinion from the folks much more in tune with this code than I am.
There was a problem hiding this comment.
I'm fine with it, though I wonder if we really need all that and not just a simplified subset of it.
If these are the only examples we have, it suggests it's quite uncommon but its prevalent enough for it to cause issues for users. |
Thank you. |
|
👋 Is the blocker on this PR still waiting for reviews from specific folks? Anything that can be done to move that along? Happy to help where I can. This change is still required to fix a bug in Sentry that is blocking us, as I understand it. |
| "cjs-module-lexer": "^1.2.2", | ||
| "module-details-from-path": "^1.0.3" | ||
| "module-details-from-path": "^1.0.3", | ||
| "@babel/helper-validator-identifier": "^7.24.7" |
There was a problem hiding this comment.
I'm fine with it, though I wonder if we really need all that and not just a simplified subset of it.
|
FWIW, it looks like this: With --trace-warnings: If I know about the ...
register('./hook.mjs', import.meta.url, {
data: {
exclude: [/fixtures\/invalid-identifier.js$/]
}
})Then, no more warning: |
|
This doesn't need to block this PR, but my guess is this kind of message: being seen by end users will result in support issues for us. :) That might be alleviated somewhat by getting that closer to something like (taking away the words "Error" and "failed"): |
That would be possible with this diff: diff --git a/hook.js b/hook.js
index b5d72f5..93664b8 100644
--- a/hook.js
+++ b/hook.js
@@ -428,7 +428,8 @@ register(${JSON.stringify(realUrl)}, _, set, ${JSON.stringify(specifiers.get(rea
//
// We log the error because there might be bugs in iitm and without this
// it would be very tricky to debug
- const err = new Error(`'import-in-the-middle' failed to wrap '${realUrl}'`)
+ const err = new Error(`'import-in-the-middle' could not wrap '${realUrl}'`)
+ err.name = 'Warning'
err.cause = cause
emitWarning(err)
|
|
In the Diagnostics WorkGroup meeting we decided that this PR has enough approvals and consensus that we can merge it. Unfortunatly now a test fails! |
|
Closing in favour of #198 |

Closes #94
Rather than trying to find a way to only export invalid identifiers in versions of Node that support exports with names like this, this PR simply skips wrapping these modules. Since modules that use exports like this are rare, it's unlikely anyone will ever want to
Hookthem and if they do we can revisit this later.@babel/helper-validator-identifierwas chosen to check for invalid identifiers because the code looks good, it sees 50m+ downloads per week, it's tested, it has no dependencies and maybe most importantly, it's CommonJs!