"Unhandled declaration" in production
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 32/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- javascript, next.js
调研方向
使用文档中说明的 Next.js 设置重现该故障,从 CDN 加载 gpu.js v2.15.2,并使用提供的 kernel 代码。将开发构建与 next build 和 next export 的输出进行比较,重点关注 gpu-browser.js 中的 Unhandled declaration stack。当 production 静态网站能够在没有该错误的情况下执行此 kernel 时,即表示完成。
由索引模型根据 Issue 内容生成。
描述

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?
- Create Next.js project.
- Add gpu.js script tag to the
_document.js:<Script src="https://unpkg.com/[email protected]/dist/gpu-browser.js" strategy="beforeInteractive" /> - Build the project with
next build(npm run build). - Generate static website with
next export. - 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,
}
)
- 主要语言
- JavaScript
- 星标
- 15.5k
- 派生
- 663
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
gpujs/gpu.js 的其他 Issue
-
难度 1/5 1 小时以内 新手友好度 65/100
-
WebGL backend silently returns all zeros for long-running kernels (no GL error, no context loss)未关闭
难度 5/5 一周以上 新手友好度 42/100
-
难度 5/5 一周以上 新手友好度 20/100
-
难度 4/5 3-5 天 新手友好度 25/100
-
难度 4/5 3-5 天 新手友好度 25/100
相似的 Issue
-
refactor
难度 2/5 半天 新手友好度 84/100
维护者通常 5 天内回复
-
translation
难度 2/5 1-3 小时 新手友好度 78/100
ciderapp/translations#87 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 88/100
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 67/100
维护者通常 1 天内回复
-
component: split-view platform: windows
难度 2/5 1-3 小时 新手友好度 74/100
zen-browser/desktop#15616 · 1 个 reaction ·
维护者通常 1 天内回复