【发布时间】:2019-09-06 12:49:46
【问题描述】:
我正在尝试使用 nuxt generate 命令生成一个 nuxt 应用程序。我想通过打开dist 文件夹中的index.html 文件来使用它。除了我加载了一些静态资产的一页之外,一切正常。我收到以下错误:
DOMException:无法构造“Worker”:脚本位于 'file:///Users/web-app/dist/_nuxt/a694c9435aa306bfdc85.worker.js' 无法从源“null”访问。 在新的 e.exports (file:///Users/web-app/dist/_nuxt/ddebbd7698f3519f1f2a.js:2:387818) 在 Object.253 (file:///Users/web-app/dist/_nuxt/ddebbd7698f3519f1f2a.js:2:41913) 在 c (file:///Users/web-app/dist/_nuxt/849a5edcbb351f009715.js:1:534) 在 Module.318 (file:///Users/web-app/dist/_nuxt/58dff71a539121ee82b0.js:1:7082) 在 c (file:///Users/web-app/dist/_nuxt/849a5edcbb351f009715.js:1:534)
这是我的nuxt.config.js 文件:
export default {
mode: 'spa',
/*
** Headers of the page
*/
head: {
title: process.env.npm_package_name || '',
meta: [
{ charset: 'utf-8' },
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },
{ hid: 'description', name: 'description', content: process.env.npm_package_description || '' }
],
link: [
{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }
]
},
/*
** Customize the progress-bar color
*/
loading: { color: '#fff' },
/*
** Global CSS
*/
css: [
'~/assets/css/tailwind.css',
'~/assets/css/all.css'
],
/*
** Plugins to load before mounting the App
*/
plugins: [
],
/*
** Nuxt.js modules
*/
modules: [
// Doc: https://axios.nuxtjs.org/usage
'@nuxtjs/axios',
'@nuxtjs/proxy',
'@nuxtjs/toast'
],
/*
** Axios module configuration
** See https://axios.nuxtjs.org/options
*/
axios: {
},
/*
** Build configuration
*/
build: {
postcss: {
plugins: {
tailwindcss: './tailwind.config.js'
}
},
/*
** You can extend webpack config here
*/
extend(config, { isDev, isClient }) {
if (!isDev) {
// relative links, please.
config.output.publicPath = "./_nuxt/";
}
return config;
}
},
router: {
mode: "hash"
}
}
我想知道是否有任何方法可以禁用我的应用中的服务人员。
【问题讨论】:
-
尝试使用 serve 之类的东西,而不是直接加载文件。
file://的原始权限与作为 Web 服务器运行完全不同。 -
@abraham 这是我无法通过调用
serve命令创建http 服务器的情况。用户将双击index.html文件打开页面。他们无法执行serve命令。只是想知道是否有任何方法可以删除service worker。 -
尝试禁用
autoRegister -
@abraham 没用。仍然显示相同的错误消息。
标签: service-worker progressive-web-apps nuxt.js