Javascript 在Angular 8中使用cli命令添加web worker后出错
Angular 8为web工作人员提供了更好的支持。我没有运气让它工作。有人知道我做错了什么吗 我跟着 使用此cli命令,我生成了web worker:Javascript 在Angular 8中使用cli命令添加web worker后出错,javascript,angular,web-worker,angular8,Javascript,Angular,Web Worker,Angular8,Angular 8为web工作人员提供了更好的支持。我没有运气让它工作。有人知道我做错了什么吗 我跟着 使用此cli命令,我生成了web worker: ng generate webWorker my-worker cli已生成my-worker.worker.ts文件和tsconfig.worker.json文件,并更新了以下文件:angular.json、tsconfig.app.json 在此之后,我收到以下错误: ERROR in node_modules/typescript/li
ng generate webWorker my-worker
cli已生成my-worker.worker.ts文件和tsconfig.worker.json文件,并更新了以下文件:angular.json、tsconfig.app.json
在此之后,我收到以下错误:
ERROR in node_modules/typescript/lib/lib.dom.d.ts(25,1): error TS6200: Definitions of the following identifiers conflict with those in another file: EventListenerOrEventListenerObject, BlobPart, HeadersInit, BodyInit, RequestInfo, DOMHighResTimeStamp, CanvasImageSource, MessageEventSource, ImageBitmapSource, TimerHandler, PerformanceEntryList, VibratePattern, AlgorithmIdentifier, HashAlgorithmIdentifier, BigInteger, NamedCurve, GLenum, GLboolean, GLbitfield, GLint, GLsizei, GLintptr, GLsizeiptr, GLuint, GLfloat, GLclampf, TexImageSource, Float32List, Int32List, BufferSource, DOMTimeStamp, FormDataEntryValue, IDBValidKey, Transferable, BinaryType, ClientTypes, EndingType, IDBCursorDirection, IDBRequestReadyState, IDBTransactionMode, KeyFormat, KeyType, KeyUsage, NotificationDirection, NotificationPermission, PushEncryptionKeyName, PushPermissionState, ReferrerPolicy, RequestCache, RequestCredentials, RequestDestination, RequestMode, RequestRedirect, ResponseType, ServiceWorkerState, ServiceWorkerUpdateViaCache, VisibilityState, WebGLPowerPreference, WorkerType, XMLHttpRequestResponseType
node_modules/typescript/lib/lib.dom.d.ts(3473,5): error TS2687: All declarations of 'privateKey' must have identical modifiers.
node_modules/typescript/lib/lib.dom.d.ts(3474,5): error TS2687: All declarations of 'publicKey' must have identical modifiers.
node_modules/typescript/lib/lib.webworker.d.ts(25,1): error TS6200: Definitions of the following identifiers conflict with those in another file: EventListenerOrEventListenerObject, BlobPart, HeadersInit, BodyInit, RequestInfo, DOMHighResTimeStamp, CanvasImageSource, MessageEventSource, ImageBitmapSource, TimerHandler, PerformanceEntryList, VibratePattern, AlgorithmIdentifier, HashAlgorithmIdentifier, BigInteger, NamedCurve, GLenum, GLboolean, GLbitfield, GLint, GLsizei, GLintptr, GLsizeiptr, GLuint, GLfloat, GLclampf, TexImageSource, Float32List, Int32List, BufferSource, DOMTimeStamp, FormDataEntryValue, IDBValidKey, Transferable, BinaryType, ClientTypes, EndingType, IDBCursorDirection, IDBRequestReadyState, IDBTransactionMode, KeyFormat, KeyType, KeyUsage, NotificationDirection, NotificationPermission, PushEncryptionKeyName, PushPermissionState, ReferrerPolicy, RequestCache, RequestCredentials, RequestDestination, RequestMode, RequestRedirect, ResponseType, ServiceWorkerState, ServiceWorkerUpdateViaCache, VisibilityState, WebGLPowerPreference, WorkerType, XMLHttpRequestResponseType
node_modules/typescript/lib/lib.webworker.d.ts(85,5): error TS2687: All declarations of 'privateKey' must have identical modifiers.
node_modules/typescript/lib/lib.webworker.d.ts(86,5): error TS2687: All declarations of 'publicKey' must have identical modifiers.
node_modules/typescript/lib/lib.webworker.d.ts(1074,5): error TS2375: Duplicate number index signature.
node_modules/typescript/lib/lib.webworker.d.ts(1360,5): error TS2375: Duplicate number index signature.
node_modules/typescript/lib/lib.webworker.d.ts(1434,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'FormData' must be of type '{ new (form?: HTMLFormElement): FormData; prototype: FormData; }', but here has type '{ new (): FormData; prototype: FormData; }'.
node_modules/typescript/lib/lib.webworker.d.ts(2170,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'Notification' must be of type '{ new (title: string, options?: NotificationOptions): Notification; prototype: Notification; readonly maxActions: number; readonly permission: NotificationPermission; requestPermission(deprecatedCallback?: NotificationPermissionCallback): Promise<...>; }', but here has type '{ new (title: string, options?: NotificationOptions): Notification; prototype: Notification; readonly maxActions: number; readonly permission: NotificationPermission; }'.
node_modules/typescript/lib/lib.webworker.d.ts(4322,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'onmessage' must be of type '(this: Window, ev: MessageEvent) => any', but here has type '(this: DedicatedWorkerGlobalScope, ev: MessageEvent) => any'.
node_modules/typescript/lib/lib.webworker.d.ts(4332,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'location' must be of type 'Location', but here has type 'WorkerLocation'.
node_modules/typescript/lib/lib.webworker.d.ts(4333,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'onerror' must be of type 'OnErrorEventHandlerNonNull', but here has type '(this: DedicatedWorkerGlobalScope, ev: ErrorEvent) => any'.
node_modules/typescript/lib/lib.webworker.d.ts(4335,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'self' must be of type 'Window', but here has type 'WorkerGlobalScope'.
node_modules/typescript/lib/lib.webworker.d.ts(4344,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'navigator' must be of type 'Navigator', but here has type 'WorkerNavigator'.
谢谢。我也有这个问题,并注意到在一个新的Angular 8项目中,所有
tsconfig.*.json
文件都在根目录中,只有根tslint.json
文件
以下是我所做的:
- 将新生成的CLI 8项目中的
、tslint.json
和tsconfig.app.json
复制到我的项目根目录中tsconfig.spec.json
- 从
目录中删除了src
、tslint.json
和tsconfig.app.json
tsconfig.spec.json
- 在
中编辑angular.json
值,以在项目根目录中而不是在tsConfig
目录中查找tsConfig文件src
src
移动到根目录并编辑其中的路径可能会更容易。我没有更改生成的文件,所以我只是从一个新项目中复制
我不知道生成Web Worker和添加
tsconfig.Worker.json
会对升级的Angular项目造成什么影响。从7升级到我添加了一个工人,效果很好。我也遇到了同样的问题。使用以下解决方案解决了此问题:如果使用SSR(服务器端渲染),请不要忘记在tsconfig.Server.json`中排除*.worker.ts:
"exclude": ["test.ts", "**/*.spec.ts", "**/*.worker.ts"],
我没有得到这个错误。worker运行正常。您使用的是什么类型脚本版本?“typescript”:“~3.4.3”和v10.16.0上的节点。尝试了一个新项目,它确实有效,但在我的主项目中它就是不起作用。还创建了一个新项目并复制了src文件夹,但仍然无法工作。不知道从何处查找(对,忘记提到在这些步骤之后我运行了ng generate webWorker
命令。如果您已经运行了generate worker命令,则需要添加“src/***/.worker.ts”
到tsconfig.app.json
中的exclude
数组中。我遵循了这条指令,它几乎成功了。我要做的是添加“webWorkerTsConfig”:“tsconfig.worker.json”
添加到architect.build.options
。注意,值tsconfig.worker.json
也必须添加到architect.lint.options.tsconfig
(它在angular.json
中显示两次)。
"exclude": ["test.ts", "**/*.spec.ts", "**/*.worker.ts"],