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

RangeError on build step #220

Closed
Hooman-studio opened this issue Sep 22, 2022 · 9 comments
Closed

RangeError on build step #220

Hooman-studio opened this issue Sep 22, 2022 · 9 comments

Comments

@Hooman-studio
Copy link

I get the follow errors on production (I am using next.js) when I run next build:

Failure loading font http://localhost:3000/models/digital-7-mono.ttf; trying fallback RangeError: Offset is outside the bounds of the DataView
    at DataView.getUint16 (<anonymous>)
    etc...

Failure loading font https://fonts.gstatic.com/s/roboto/v18/KFOmCnqEu92Fr1Mu4mxM.woff RangeError: Offset is outside the bounds of the DataView
    at DataView.getUint16 (<anonymous>)
    etc...

When running next dev this error doesn't come up.

-I am using troika-three-text via the drei component. I found out this uses the preloadFont function as well, I am not sure that that is relevant, but just in case it is.

-Error happens both in Chrome and Safari.

@lojjic
Copy link
Collaborator

lojjic commented Sep 22, 2022

Do you have somewhere showing this bug in action that I could look at?

@max-ch9i
Copy link

Here's a reproducible example: https://stackblitz.com/edit/nextjs-fznkmq?file=package.json,next.config.js

I've narrowed it down to the options swcMinify and next version 12.3.1. Steps to reproduce:

  1. Set swcMinify: true in next.config.js.
  2. Run yarn && yarn next build && yarn next start.

The error is gone when swcMinify: false.

Another issue that manifested in different behaviours on prod and dev builds, which might be related, is pmndrs/react-three-fiber#2533.

@lojjic
Copy link
Collaborator

lojjic commented Sep 28, 2022

Hmmm, I don't get that error when setting swcMinify: true and running that command in your stackblitz. Are there any additional steps needed?

@max-ch9i
Copy link

Tried that myself again and couldn't reproduce either.
However, when I tried npx next build && npx next start instead, the error appeared again:
Screenshot 2022-09-28 at 08 10 24

@lojjic
Copy link
Collaborator

lojjic commented Sep 28, 2022

Thanks, that worked to reproduce it.

It seems there is a bug in how swcMinify is rewriting the code. This seems to be the culprit:

image

That r < r + i loop condition is this in the original code:

offset < offset0 + length

It seems it's merging two separate variables (offset which is incremented and offset0 which remains static) into the same r variable...? That makes the condition always true and it would be an infinite loop if the DataView read didn't start throwing past the array length.

I'm not sure where to point you to get it fixed in the minifier.

@max-ch9i
Copy link

Thanks for debugging. I've referenced your find in this thread: vercel/next.js#30237 (comment)

@max-ch9i
Copy link

Seems like the issue is fixed on canary: vercel/next.js#30237 (reply in thread)

@lojjic
Copy link
Collaborator

lojjic commented Oct 1, 2022

Great! I'm going to close this issue then. 🎉

@lojjic lojjic closed this as completed Oct 1, 2022
@vasco3
Copy link

vasco3 commented Nov 15, 2022

I'm seeing this issue in next.js 13.0.3
did anyone found a solution?
it only happens in production. It runs fine in next dev

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