next.js - ReferenceError:未定义 AudioBuffer
问题描述
我正在尝试在 next.js 反应项目中使用tone.js。当我运行或构建时,我收到此错误“ReferenceError: AudioBuffer is not defined”
我已经在代码和框中隔离了tone.js 代码,它运行良好。 https://codesandbox.io/s/tonejs-react-pink-noise-generator-pfnl0?file=/src/App.js
但不在 next.js 应用程序中
ReferenceError: AudioBuffer is not defined
at ki (/node_modules/tone/build/Tone.js:1:117922)```
解决方案
AudioBuffer是 Web 浏览器的东西,它在 node.js 中不存在。您收到的错误是因为使用的代码AudioBuffer
无法在服务器上运行。您只需要在浏览器中实例化这部分代码。这通常在useEffect
钩子中完成,或者在服务器上,您可以首先检查window
对象是否已定义。
推荐阅读
- json - DotNet 5.0 Core MVC - 与 JsonPatchDocument 一起使用 - PATCH 不起作用 - 找不到 404
- java - 上传一组 .png 文件并保存到 HashMap
- flutter - Flutter(dart)文件上传,进度条-文件上传流在上传过程中不回馈数据
- airflow - 任务缺少 start_date 参数
- python - 如何在 v.DataTable 中选择一个元素?
- javascript - jQuery mobile 只使用一个 Event
- jquery - jQuery UI(可拖动):放置后元素未放置在我的光标位置
- reactjs - 警告:无效的 DOM 属性“类”。你的意思是“className”吗?
- android - Firebase onCall 函数将结果保存到 android 中的变量中
- mapr - 带有 mapr 客户端的节点是否需要访问我要使用 distcp 复制的文件?