我在摆弄服务人员,并想使用 sw-toolbox,它有一种支持快速样式路由的方法。但是,当我使用这些行的任何版本导入它时:
importScripts('node_modules/sw-toolbox/sw-toolbox.js');
importScripts('../node_modules/sw-toolbox/sw-toolbox.js');
importScripts('/node_modules/sw-toolbox/sw-toolbox.js');
我收到以下错误:
A bad HTTP response code (404) was received when fetching the script.
:3000/node_modules/sw-toolbox/sw-toolbox.js Failed to load resource: net::ERR_INVALID_RESPONSE
到目前为止,这是我的服务人员代码:
(global => {
'use strict';
//Load the sw-toolbox library
importScripts('node_modules/sw-toolbox/sw-toolbox.js');
//Ensure that our service worker takes control of the page asap
global.addEventListener('install', event => event.waitUntil(global.skipWaiting()));
global.addEventListener('activate', event => event.waitUntil(global.clients.claim()));
})(self);
我究竟做错了什么?