最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

使用worker

IT培训 admin 5浏览 0评论

使用worker

我正在尝试在Typescript中使用WebWorkers,但遇到了一个问题。我已经安装了@ types / node并更新了所有内容。 'worker_threads'不再处于实验阶段,它处于node.js的稳定版本中。

这是我的打字稿配置:

{
  "compilerOptions": {
    "target": "esnext",
    "module": "esnext",
    "strict": true,
    "jsx": "preserve",
    "importHelpers": true,
    "moduleResolution": "node",
    "experimentalDecorators": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "sourceMap": true,
    "baseUrl": ".",
    "types": [
      "webpack-env",
      "node",
      "dom-mediacapture-record"
    ],
    "paths": {
      "@/*": [
        "src/*"
      ]
    },
    "lib": [
      "esnext",
      "dom",
      "dom.iterable",
      "scripthost"
    ]
  },
  "include": [
    "src/**/*.ts",
    "src/**/*.tsx",
    "src/**/*.vue",
    "tests/**/*.ts",
    "tests/**/*.tsx"
  ],
  "exclude": [
    "node_modules"
  ]
}

[当我试图这样输入我的打字稿文件时:

import { Worker } from 'worker_threads';

出现错误:


This dependency was not found:

* worker_threads in ./src/SpeechRecognizer/SpeechRecognizer.ts

To install it, you can run: npm install --save worker_threads
Type checking and linting in progress...
No type errors found
No lint errors found
Version: typescript 3.6.3, tslint 5.20.0

[我也将Vue.js用于前端。我已经尝试了所有可能找到的东西,因此我很乐意提供帮助。如果这不起作用,我将适当地切换到JavaScript。谢谢。

回答如下:

您可以使用npm软件包“ worker-loader”。转到下面的链接https://www.npmjs/package/worker-loader并参考“与TypeScript集成”部分

使用worker

我正在尝试在Typescript中使用WebWorkers,但遇到了一个问题。我已经安装了@ types / node并更新了所有内容。 'worker_threads'不再处于实验阶段,它处于node.js的稳定版本中。

这是我的打字稿配置:

{
  "compilerOptions": {
    "target": "esnext",
    "module": "esnext",
    "strict": true,
    "jsx": "preserve",
    "importHelpers": true,
    "moduleResolution": "node",
    "experimentalDecorators": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "sourceMap": true,
    "baseUrl": ".",
    "types": [
      "webpack-env",
      "node",
      "dom-mediacapture-record"
    ],
    "paths": {
      "@/*": [
        "src/*"
      ]
    },
    "lib": [
      "esnext",
      "dom",
      "dom.iterable",
      "scripthost"
    ]
  },
  "include": [
    "src/**/*.ts",
    "src/**/*.tsx",
    "src/**/*.vue",
    "tests/**/*.ts",
    "tests/**/*.tsx"
  ],
  "exclude": [
    "node_modules"
  ]
}

[当我试图这样输入我的打字稿文件时:

import { Worker } from 'worker_threads';

出现错误:


This dependency was not found:

* worker_threads in ./src/SpeechRecognizer/SpeechRecognizer.ts

To install it, you can run: npm install --save worker_threads
Type checking and linting in progress...
No type errors found
No lint errors found
Version: typescript 3.6.3, tslint 5.20.0

[我也将Vue.js用于前端。我已经尝试了所有可能找到的东西,因此我很乐意提供帮助。如果这不起作用,我将适当地切换到JavaScript。谢谢。

回答如下:

您可以使用npm软件包“ worker-loader”。转到下面的链接https://www.npmjs/package/worker-loader并参考“与TypeScript集成”部分

与本文相关的文章

发布评论

评论列表 (0)

  1. 暂无评论