类型错误:使用流浏览器时,类扩展值未定义不是构造函数或 null

发布于 2025-01-14 09:01:54 字数 1888 浏览 1 评论 0原文

使用 stream-browserify 导入 Transform 类并在代码中扩展它时,导致浏览器控制台中出现以下异常

AudioUtils.ts:52 Uncaught TypeError: Class extends value undefined is not a constructor or null
    at Module../src/components/AudioUtils.ts (AudioUtils.ts:52:1)
    at Module.options.factory (react refresh:6:1)
    at __webpack_require__ (bootstrap:24:1)
    at fn (hot module replacement:61:1)
    at Module../src/components/TController.ts (TConfig.ts:10:1)
    at Module.options.factory (react refresh:6:1)
    at __webpack_require__ (bootstrap:24:1)
    at fn (hot module replacement:61:1)
    at Module../src/components/STT.tsx (AudioUtils.ts:67:1)
    at Module.options.factory (react refresh:6:1)

这是 AudioUtils.ts 的片段code>

import { Transform } from 'stream'

export class EncodePcmStream extends Transform {
    _transform(chunk: any, encoding: string, callback: TransformCallback) {
        const buffer = encodePcm(chunk); // encodePcm is a local function
        this.push(buffer);
        callback();
    }
}

这是 package.json 的片段,

{
  "name": "app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@types/jest": "^27.4.1",
    "@types/node": "^16.11.26",
    "@types/react-dom": "^17.0.2",
    "buffer": "^6.0.3",
    "microphone-stream": "^6.0.1",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-scripts": "5.0.0",
    "stream-browserify": "^3.0.0",
    "typescript": "^4.6.2"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "devDependencies": {
    "@types/readable-stream": "2.3.13"
  },
  "type": "module"
}
  • 我在这里检查了大多数具有类似错误的问题,但没有一个解决方案有效。
  • 我使用 dpdm 来检查循环依赖关系,并且没有报告循环依赖关系。

While using stream-browserify to import Transform class and extend it in the code causing the following exception in the browser console

AudioUtils.ts:52 Uncaught TypeError: Class extends value undefined is not a constructor or null
    at Module../src/components/AudioUtils.ts (AudioUtils.ts:52:1)
    at Module.options.factory (react refresh:6:1)
    at __webpack_require__ (bootstrap:24:1)
    at fn (hot module replacement:61:1)
    at Module../src/components/TController.ts (TConfig.ts:10:1)
    at Module.options.factory (react refresh:6:1)
    at __webpack_require__ (bootstrap:24:1)
    at fn (hot module replacement:61:1)
    at Module../src/components/STT.tsx (AudioUtils.ts:67:1)
    at Module.options.factory (react refresh:6:1)

Here is the snippet of AudioUtils.ts

import { Transform } from 'stream'

export class EncodePcmStream extends Transform {
    _transform(chunk: any, encoding: string, callback: TransformCallback) {
        const buffer = encodePcm(chunk); // encodePcm is a local function
        this.push(buffer);
        callback();
    }
}

Here is the snippet of package.json

{
  "name": "app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@types/jest": "^27.4.1",
    "@types/node": "^16.11.26",
    "@types/react-dom": "^17.0.2",
    "buffer": "^6.0.3",
    "microphone-stream": "^6.0.1",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-scripts": "5.0.0",
    "stream-browserify": "^3.0.0",
    "typescript": "^4.6.2"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "devDependencies": {
    "@types/readable-stream": "2.3.13"
  },
  "type": "module"
}
  • I checked most of the questions with similar error here but none of the solutions worked.
  • I used dpdm to check circular dependency and there are no circular dependency that it reported.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文