使用 eslint nuxt 模块通过 nuxt 3 设置 eslint

问题描述 投票:0回答:1

我正在尝试使用 Nuxt 3.2 设置 eslint,但是每当我运行我的应用程序时它就会崩溃。以下是我的设置:

package.json

"devDependencies": {
    "@nuxt/eslint-config": "^0.1.1",
    "@nuxtjs/eslint-module": "^4.1.0",
    "eslint": "^8.43.0",
    "nuxt": "3.2.0"
  },  

.eslintrc

{
    "extends": ["@nuxt/eslint-config"]
}  

nuxt.config.ts

modules: ["@pinia/nuxt", "@nuxtjs/eslint-module"],  

错误

ERROR  Cannot start nuxt:  Cannot find module 'ajv/dist/compile/codegen'                                                19:54:58
Require stack:
- C:\Work\Projects\lims-frontend\node_modules\ajv-keywords\dist\definitions\typeof.js
- C:\Work\Projects\lims-frontend\node_modules\ajv-keywords\dist\keywords\typeof.js
- C:\Work\Projects\lims-frontend\node_modules\ajv-keywords\dist\keywords\index.js
- C:\Work\Projects\lims-frontend\node_modules\ajv-keywords\dist\index.js
- C:\Work\Projects\lims-frontend\node_modules\schema-utils\dist\validate.js
- C:\Work\Projects\lims-frontend\node_modules\schema-utils\dist\index.js
- C:\Work\Projects\lims-frontend\node_modules\eslint-webpack-plugin\dist\options.js                                      19:54:34  
- C:\Work\Projects\lims-frontend\node_modules\eslint-webpack-plugin\dist\index.js

  Require stack:
  - node_modules\ajv-keywords\dist\definitions\typeof.js
  - node_modules\ajv-keywords\dist\keywords\typeof.js
  - node_modules\ajv-keywords\dist\keywords\index.js
  - node_modules\ajv-keywords\dist\index.js
  - node_modules\schema-utils\dist\validate.js
  - node_modules\schema-utils\dist\index.js
  - node_modules\eslint-webpack-plugin\dist\options.js
  - node_modules\eslint-webpack-plugin\dist\index.js
  at Function.Module._resolveFilename (node:internal/modules/cjs/loader:995:15)
  at Function.Module._load (node:internal/modules/cjs/loader:841:27)
  at Module.require (node:internal/modules/cjs/loader:1067:19)
  at require (node:internal/modules/cjs/helpers:103:18)
  at Object.<anonymous> (node_modules\ajv-keywords\dist\definitions\typeof.js:3:19)
  at Module._compile (node:internal/modules/cjs/loader:1165:14)
  at Object.Module._extensions..js (node:internal/modules/cjs/loader:1219:10)
  at Module.load (node:internal/modules/cjs/loader:1043:32)
  at Function.Module._load (node:internal/modules/cjs/loader:878:12)
  at Module.require (node:internal/modules/cjs/loader:1067:19)
nuxt.js eslint nuxtjs3
1个回答
0
投票

在根目录中创建一个

.eslintrc
文件。

使用 JavaScript 安装

@nuxtjs/eslint-config
并将它们添加到 eslintrc 文件中

{
  "extends": ["@nuxtjs/eslint-config"]
}

使用 TypeScript 安装

@nuxtjs/eslint-config-typescript
并将它们添加到 eslintrc

{
  "extends": ["@nuxtjs/eslint-config-typescript"]
}

我认为问题在于您使用的是

@nuxt/eslint-config
而不是
@nuxtjs/eslint-config

© www.soinside.com 2019 - 2024. All rights reserved.