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

Show error which occurs in vercel/vercel ci tests #447

Conversation

jeffsee55
Copy link
Contributor

We're seeing an error with 0.27.4 in our tests while trying to upgrade

https://github.com/vercel/vercel/actions/runs/11487918780/job/31973631387?pr=12109

I was able to isolate it down to this code snippet. Which is from an admittedly old module depended upon by Next version 9

https://www.npmjs.com/package/normalize-url/v/3.3.0?activeTab=code

@jeffsee55 jeffsee55 requested review from ijjk, styfle and a team as code owners October 24, 2024 22:21
@jeffsee55 jeffsee55 marked this pull request as draft October 25, 2024 21:08
@@ -0,0 +1 @@
const URLParser = typeof window === 'undefined' ? URL : 'b'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test fails with

 TypeError: Class constructor URL cannot be invoked without 'new'

The offending node is the URL Identifier, and I'm not able to see where it's getting invoked, I'm guessing due to some async nature of the code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a regression from PR #429 ?

It added url to global, although this test doesn't have require('url') so may not be related.

Or maybe it was from the URL global here?

URL: URL,

Copy link
Contributor

@onsclom onsclom Oct 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More info on this:

  • The URL global you linked does seem to be the culprit!
  • Removing URL from globals makes this case work, but breaks other cases
  • The core problem exists well before 0.27.4, but 0.27.4 seems to trace more files which causes our test to hit this URL core problem now

Debugging this is tricky since the stack trace is very unhelpful. For example, replacing URL: URL with URL: () => console.trace('Called URL') and running this reproduction test gives the very unhelpful stack trace:

Trace: Called URL
    at Object.URL [as then] (/Users/onsclom/projects/nft/src/analyze.ts:188:13)

I can't figure out where URL is getting called from. Seems like from the then of some promise, but which one?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@styfle Do you know how URL is getting invoked here? Happy to make a PR fixing this, but stuck on finding where exactly URL is getting invoked.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its probably from computePureStaticValue() which is basically a static analysis form of eval() so it sets globals vars and local vars to try to compute a value.

async function computePureStaticValue(expr: Node, computeBranches = true) {

@onsclom onsclom closed this in #458 Dec 19, 2024
onsclom added a commit that referenced this pull request Dec 19, 2024
`nodeFileTrace` errors on `const URLParser = typeof window ===
'undefined' ? URL : 'b'` with `TypeError: Class constructor URL cannot
be invoked without 'new'`.

This is because this code:

```ts
async function ConditionalExpression() {
  return {
    test: 'foo',
    then: URL,
    else: 'bar',
  };
}
await ConditionalExpression();
```

calls `URL()` since `ConditionalExpression` is an async function
returning a
[thenable](https://masteringjs.io/tutorials/fundamentals/thenable).

Solution: rename all `.then` fields to `.ifTrue` since `then` is
reserved for thenables.

Closes #447
@styfle styfle deleted the jeffsee/zero-2474-update-vercelnft-to-version-0274-in-vercelvercel branch December 19, 2024 01:05
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

Successfully merging this pull request may close these issues.

3 participants