Reputation: 21
Im trying to use WebWorkers in Typescript and I have encoutered a problem. I have installed @types/node and updated everything. 'worker_threads' is not longer experimental and is in stable version of node.js.
This is my typescript config:
{
"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"
]
}
When Im trying to do import in my typescript file like this:
import { Worker } from 'worker_threads';
Im getting error:
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
Also Im using Vue.js for frontend. I have already tried everything I could find so Im glad for every help. If this wont work I will propably switch to JavaScript. Thanks.
Upvotes: 2
Views: 8926
Reputation: 6044
You can use the npm package 'worker-loader'. Goto the below link https://www.npmjs.com/package/worker-loader and refer the section 'Integrating with TypeScript'
Upvotes: 0