npm Nuxt致命错误类型错误:无法析构“this”的属性“nuxt”,因为它未定义,Nuxt Js

thtygnil  于 2023-02-19  发布在  其他
关注(0)|答案(1)|浏览(183)

当我尝试运行npm时,在我的nuxt项目中运行dev,我得到了一个类似这样的错误。

Using default Tailwind CSS file from runtime/tailwind.css                                                                       nuxt:tailwindcss 21:02:57

 FATAL  Cannot destructure property 'nuxt' of 'this' as it is undefined.                                                                           21:02:57

  at postcss8Module (node_modules/@nuxt/postcss8/dist/index.js:15:10)
  at installModule (node_modules/@nuxt/kit/dist/index.mjs:435:21)
  at async setup (node_modules/@nuxtjs/tailwindcss/dist/module.mjs:186:7)
  at async ModuleContainer.normalizedModule (node_modules/@nuxt/kit/dist/index.mjs:167:5)
  at async ModuleContainer.addModule (node_modules/@nuxt/core/dist/core.js:167:20)
  at async ModuleContainer.ready (node_modules/@nuxt/core/dist/core.js:34:7)
  at async Nuxt._init (node_modules/@nuxt/core/dist/core.js:342:5)

json。我刚刚使用“npm init nuxt-app myhealth”创建了一个新的nuxt项目

{
  "name": "myhealth",
  "version": "1.0.0",
  "private": true,
  "scripts": {
    "dev": "nuxt",
    "build": "nuxt build",
    "start": "nuxt start",
    "generate": "nuxt generate"
  },
  "dependencies": {
    "core-js": "^3.25.3",
    "nuxt": "^2.15.8",
    "vue": "^2.7.10",
    "vue-server-renderer": "^2.7.10",
    "vue-template-compiler": "^2.7.10"
  },
  "devDependencies": {
    "@nuxtjs/tailwindcss": "^5.3.3",
    "postcss": "^8.4.17"
  }
}
lxkprmvk

lxkprmvk1#

通过以下步骤解决此问题:
1.按照tailwind文档中的说明再次安装开发依赖项
1.删除"@nuxtjs/tailwindcss "并将"@nuxt/postcss8"添加到nuxt.config.js中
1.配置nuxt.config.js构建属性,方法是添加

build: {
    postcss: {
      plugins: {
        tailwindcss: {},
        autoprefixer: {},
      },
    },
},

参考:https://tailwindcss.com/docs/guides/nuxtjs

相关问题