Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

"Unhandled declaration" in production

Aperta
#776 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
32/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
javascript, next.js

Direzione di ricerca

Riproduci il malfunzionamento con la configurazione documentata di Next.js, caricando gpu.js v2.15.2 dal CDN e utilizzando il codice del kernel fornito. Confronta la build di sviluppo con l’output di next build e next export, concentrandoti sull’Unhandled declaration stack in gpu-browser.js. Il lavoro è completato quando il sito statico di produzione può eseguire questo kernel senza l’errore.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

A GIF or MEME to give some spice of the internet

What is wrong?

I get the following error when trying to use gpu.js on production (optimized code):

Uncaught Error: Unhandled declaration
    at WebGL2FunctionNode.astVariableDeclaration (gpu-browser.js:12600:17)
    at WebGL2FunctionNode.astGeneric (gpu-browser.js:8023:23)
    at WebGL2FunctionNode.astBlockStatement (gpu-browser.js:12555:14)
    at WebGL2FunctionNode.astGeneric (gpu-browser.js:8007:23)
    at WebGL2FunctionNode.astForStatement (gpu-browser.js:12455:12)
    at WebGL2FunctionNode.astGeneric (gpu-browser.js:8017:23)
    at WebGL2FunctionNode.astFunction (gpu-browser.js:11962:12)
    at WebGL2FunctionNode.astFunctionExpression (gpu-browser.js:8095:17)
    at WebGL2FunctionNode.astGeneric (gpu-browser.js:7991:23)
    at WebGL2FunctionNode.toString (gpu-browser.js:7437:32)

Where does it happen?

On my static website built with Next.js that loads gpu.js from CDN. However, it perfectly works on local server with unoptimized code in a dev mode.

How do we replicate the issue?

  1. Create Next.js project.
  2. Add gpu.js script tag to the _document.js: <Script src="https://unpkg.com/[email protected]/dist/gpu-browser.js" strategy="beforeInteractive" />
  3. Build the project with next build (npm run build).
  4. Generate static website with next export.
  5. Host the static website on a server and try to use gpu.js there.

I suppose babel does something with my kernel code, idk.

How important is this (1-5)?

4

Other Comments

I use gpu.js v2.15.2. Here is my kernel code. Seems like nothing special:

const createKernel = outputLength => new window.GPU({
    mode: "gpu",
}).createKernel(
    function (videoPixels, emojiPixels, emojiPixelsLength, brightness) {
        let lowestDistanceIn3d = Infinity
        let lowestDistanceEmojiPixelIndex = 0

        for (let j = 0, i = 0; j < emojiPixelsLength; j += 3) {
            const emojiPixel = [emojiPixels[j], emojiPixels[j + 1], emojiPixels[j + 2]]

            const videoPixelOffset = this.thread.x * 4
            const videoPixel = [
                videoPixels[videoPixelOffset],
                videoPixels[videoPixelOffset + 1],
                videoPixels[videoPixelOffset + 2],
            ]

            const distanceIn3d = Math.sqrt(
                Math.pow(emojiPixel[0] - videoPixel[0] * brightness, 2) +
                    Math.pow(emojiPixel[1] - videoPixel[1] * brightness, 2) +
                    Math.pow(emojiPixel[2] - videoPixel[2] * brightness, 2)
            )

            if (lowestDistanceIn3d > distanceIn3d) {
                lowestDistanceIn3d = distanceIn3d
                lowestDistanceEmojiPixelIndex = i
            }

            i++
        }
        return lowestDistanceEmojiPixelIndex
    },
    {
        output: [outputLength],
        loopMaxIterations: 9999999,
    }
)
Lingua principale
JavaScript
Stelle
15.5k
Fork
663
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di gpujs/gpu.js

Tutte le issue di gpujs/gpu.js

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.