我目前正在从事一个相当大的项目,该项目具有许多不同的依赖关系,分布在许多文件中。首先,我运行 NPM 和 webpack 来管理大部分依赖项。在工作箱文档中,我有两种不同的方式来集成它,或者通过 webpack(实际上只是一个示例)或通过 NPM。我决定尝试使用 NPM。我运行了以下命令:
npm install --save-dev workbox-sw
这将 workbox-sw 添加到package.json
依赖项部分。但是,每当我尝试使用以下方法导入时:
import Workbox-SW from 'workbox-sw'
它给了我以下错误:
未捕获的 WorkboxError:工作箱引发错误,错误代码为:;'not-in-sw'
我尝试了其他一些方法,但只是天真。webpack 文档肯定乏善可陈,我想避免安装其他依赖项以使其正常运行。其他一些重要说明:
- 我正在使用 Vue.js
- 我创建了一些不同的组件,它们通过路由进行交互。我正在尝试导入特定组件。
这是完整的错误消息:
Uncaught WorkboxError: An error was thrown by workbox with error code: ;'not-in-sw'
at eval (webpack-internal:///259:175:40)
at Object.<anonymous> (http://localhost:8080/app.js:2361:1)
at __webpack_require__ (http://localhost:8080/app.js:660:30)
at fn (http://localhost:8080/app.js:86:20)
at eval (webpack-internal:///173:3:69)
at Object.<anonymous> (http://localhost:8080/app.js:1795:1)
at __webpack_require__ (http://localhost:8080/app.js:660:30)
at fn (http://localhost:8080/app.js:86:20)
at eval (webpack-internal:///239:8:3)
at Object.<anonymous> (http://localhost:8080/app.js:2239:1)
WorkboxError @ workbox-sw.prod.v2.1.1.mjs?efda:155
(anonymous) @ workbox-sw.prod.v2.1.1.mjs?efda:175
(anonymous) @ app.js:2361
__webpack_require__ @ app.js:660
fn @ app.js:86
(anonymous) @ 173:3
(anonymous) @ app.js:1795
__webpack_require__ @ app.js:660
fn @ app.js:86
(anonymous) @ HomeView.vue?afbe:8
(anonymous) @ app.js:2239
__webpack_require__ @ app.js:660
fn @ app.js:86
(anonymous) @ index.js?3672:1
(anonymous) @ app.js:1809
__webpack_require__ @ app.js:660
fn @ app.js:86
(anonymous) @ main.js?1c90:1
(anonymous) @ app.js:1616
__webpack_require__ @ app.js:660
fn @ app.js:86
(anonymous) @ app.js:2368
__webpack_require__ @ app.js:660
(anonymous) @ app.js:709
(anonymous) @ app.js:712