troika
troika copied to clipboard
RangeError on build step
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 <Text /> 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.
Do you have somewhere showing this bug in action that I could look at?
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:
- Set
swcMinify: true
in next.config.js. - 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 https://github.com/pmndrs/react-three-fiber/issues/2533.
Hmmm, I don't get that error when setting swcMinify: true
and running that command in your stackblitz. Are there any additional steps needed?
Tried that myself again and couldn't reproduce either.
However, when I tried npx next build && npx next start
instead, the error appeared again:
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](https://user-images.githubusercontent.com/138124/192833267-f0701a77-c8ea-429c-b111-8c695d523e65.png)
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.
Thanks for debugging. I've referenced your find in this thread: https://github.com/vercel/next.js/discussions/30237#discussioncomment-3755143
Seems like the issue is fixed on canary: https://github.com/vercel/next.js/discussions/30237#discussioncomment-3769166
Great! I'm going to close this issue then. 🎉