按照 Google Workbox 说明,我被告知应在 serviceWorker.js 中包含的第一件事是:
importScripts('https://storage.googleapis.com/workbox-cdn/releases/4.3.1/workbox-sw.js');
但是尝试运行 npm run start 给了我:
importScripts' is not defined no-undef
importScripts 通常在哪里定义,以及如何在使用 Create React App 2 创建(而不是弹出)的基于 Typescript 的 React 项目中使用它?
最佳答案
在 tsconfig.json 文件中 compilerOptions
的 lib
属性中添加 WebWorker
。示例
{
"compilerOptions": {
...
"lib": [
...,
"WebWorker"
]
}
}
附注进行更改后,重新启动 IDE。虽然这不是必需的,但在大多数情况下,它是有效的:)
关于reactjs - 基于 Typescript 的 React : importScripts() gives: 'importScripts' is not defined no-undef,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58936448/