node.js - 无法在 nuxt3 中获取动态导入的模块

标签 node.js vuejs3 vuetify.js progressive-web-apps nuxt3

我正在学习 nuxt3,我一直被这个问题困扰,并且我已经浏览了一些有关此错误的帖子,但所有解决方案都不适合我。 我正在开发一个 nuxt3 应用程序,带有来自 kevinmarrec/nuxt-pwa-module 的 vuetify、Bootstrap 和 pwa 模块.

当我使用 npm run dev 运行应用程序时,一切似乎都开始正常构建,但是在首先加载页面后,我得到了页面“Hello nuxt”的正确 View ,但在 2-4 秒内页面更改为:

500 Failed to fetch dynamically imported module: http://localhost:3000/_nuxt/pages/index.vue

我尝试在 Windows 10 和内核:Linux 6.0.0-kali6-amd64 上解决此问题,但没有成功。在这两个平台上,我都使用 Node v18.14.1。

index.vue

      <template>
         <div>
            <h1>Hello nuxt</h1>
       </div>
     </template>
     <script>
        export default { }
     </script>
     <style scoped> </style>

下面是plugins文件夹vuetify.ts文件的配置

     import { createVuetify } from 'vuetify'
     import * as components from 'vuetify/components'
     import * as directives from 'vuetify/directives'

     export default defineNuxtPlugin(nuxtApp => {
          const veutify = createVuetify({
                    ssr: true,
                    components,
                    directives,
            });
      nuxtApp.vueApp.use(veutify)
     });

下面是nuxt.config.ts文件的配置

     export default defineNuxtConfig({
     nitro: {
        esbuild: {
          options: {
          target: 'esnext'
            }
         }
       },
     css: ["vuetify/lib/styles/main.sass",
         '@mdi/font/css/materialdesignicons.min.css',
         "bootstrap/dist/css/bootstrap.min.css"
         ],
    build: {
      transpile: ["vuetify"],
     },
   vite: {
    define: {
        "process.env.DEBUG": false,
        },
    },
   modules: ['@kevinmarrec/nuxt-pwa'],
   pwa: {
      workbox: {
      enabled: true
        }
   },
   runtimeConfig: {
       public: {
         BASE_URL: 'some fallback value',
        },
   },
})

package.json 文件

    {
      "private": true,
      "scripts": {
      "build": "nuxt build",
      "dev": "nuxt dev",
      "generate": "nuxt generate",
      "preview": "nuxt preview",
      "postinstall": "nuxt prepare"
    },
      "devDependencies": {
        "@kevinmarrec/nuxt-pwa": "^0.16.2",
        "@nuxtjs/pwa": "^3.3.5",
        "nuxt": "^3.2.2"
       },
     "dependencies": {
       "@mdi/font": "^7.1.96",
       "bootstrap": "^5.2.3",
       "sass": "^1.58.3",
       "vee-validate": "^4.7.4",
       "vuetify": "^3.1.5"
        }
       }

下面是我收到的错误

enter image description here

在控制台上我收到此错误和警告

enter image description here

最后这个警告如下

enter image description here

我到底做错了什么触发了这个,这似乎是一个大块。?

最佳答案

我也遇到了同样的错误。我通过运行 cleanup 命令解决了这个问题 -

npx nuxi clean|cleanup [rootDir]

然后

npm run dev 

doc link

The cleanup command removes common generated Nuxt files and caches, including:

  • .nuxt
  • .output
  • node_modules/.vite
  • node_modules/.cache

关于node.js - 无法在 nuxt3 中获取动态导入的模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75510099/

相关文章:

node.js - 适用于 Azure 的 iisnode 的 if(require.main) 模式

vue.js - 无法在 vue 3 组合 api 中的组件上使用模板引用

javascript - Vuetify - 如何处理 <v-btn>​​ 上的点击事件?

javascript - 如何使用 vue.js 将服务器端数据绑定(bind)到某些 html 元素

node.js - 为什么 Debian/Ubuntu 上只能使用过时的 NPM 版本?

javascript - 如何确定用户是否从后端单击了前端的按钮?

typescript - ESLint:解析错误:意外的 token :

vue.js - 处理 nuxt3 usefetch 上的错误

javascript - 名为 slot "activator"的 Vue JS Vuetify 菜单未绑定(bind)到模板,而是转到 "default"

javascript - vuetify模板中的字体,如何更改?