javascript - 执行 eslint 时找不到模块“json-schema”错误
问题描述
我面临一个问题,我还没有在互联网上找到解决方案。我发现了一些类似的情况,但解决方案(主要是安装某些东西或清除缓存)在我的情况下不起作用。
我为我的 react 项目安装了以下包(package.json):
"devDependencies": {
"@babel/core": "^7.9.6",
"@babel/preset-env": "^7.9.6",
"@babel/preset-react": "^7.9.4",
"@ngtools/json-schema": "^1.1.0",
"@types/react": "^16.9.35",
"@types/react-dom": "^16.9.8",
"@types/react-redux": "^7.1.8",
"@types/react-router": "^5.1.7",
"@types/react-router-dom": "^5.1.5",
"@typescript-eslint/eslint-plugin": "^2.32.0",
"@typescript-eslint/parser": "^2.32.0",
"axios": "^0.19.2",
"babel-loader": "^8.1.0",
"bootstrap": "^4.4.1",
"cross-env": "^7.0",
"eslint": "^6.8.0",
"eslint-config-airbnb": "^18.1.0",
"eslint-config-google": "^0.14.0",
"eslint-plugin-import": "^2.20.2",
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-react": "^7.19.0",
"eslint-plugin-react-hooks": "^2.5.1",
"jquery": "^3.5.1",
"laravel-mix": "^5.0.1",
"lodash": "^4.17.13",
"popper.js": "^1.12",
"react": "^16.2.0",
"react-dom": "^16.2.0",
"react-redux": "^7.2.0",
"redux": "^4.0.5",
"redux-thunk": "^2.3.0",
"resolve-url-loader": "^3.1.0",
"sass": "^1.26.5",
"sass-loader": "^8.0.0",
"source-map-loader": "^0.2.4",
"ts-loader": "^7.0.4",
"typescript": "^3.8.3"
},
"dependencies": {
"@emotion/core": "^10.0.28",
"@fortawesome/fontawesome-free": "^5.13.0",
"formik": "^2.1.4",
"moment": "^2.25.3",
"moment-timezone": "^0.5.28",
"react-currency-format": "^1.0.0",
"react-data-table-component": "^6.9.1",
"react-datepicker": "^2.15.0",
"react-flash-message": "^1.0.2",
"react-intl": "^4.5.3",
"react-loader-spinner": "^3.1.14",
"react-moment": "^0.9.7",
"react-pure-loaders": "^3.0.1",
"react-router-dom": "^5.2.0",
"redux-logger": "^3.0.6",
"styled-components": "^5.1.0",
"yup": "^0.28.5"
}
每次我执行 eslint 来检查文件时,我都会收到以下错误:
Error: Failed to load parser '@typescript-eslint/parser' declared in '.eslintrc.js': Cannot find module 'json-schema'
我正在执行这样的命令(在 Windows 上):
node_modules.bin\eslint {我的 .tsx 文件的路径}
这是我的.eslintrc.js
(默认生成的 airbnb 样式指南):
module.exports = {
"env": {
"browser": true,
"es6": true
},
"extends": [
"plugin:react/recommended",
"airbnb"
],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 2018,
"sourceType": "module"
},
"plugins": [
"react",
"@typescript-eslint"
],
"rules": {
}
};
有人对我有解决方案吗?我已经尝试安装几个json-schema
包并且已经清除了缓存/node_modules 文件夹。可悲的是,到目前为止没有任何帮助。
解决方案
今天遇到了同样的问题。好像有更新了
在package.json降级:
"@typescript-eslint/eslint-plugin": "^2.32.0",
"@typescript-eslint/parser": "^2.32.0",
至:
"@typescript-eslint/eslint-plugin": "2.25.0",
"@typescript-eslint/parser": "2.25.0",
暂时解决了这个问题。
希望这可以帮助!
推荐阅读
- java - Erro 在heroku BCryptPasswordEncoder 上部署应用程序
- answer-set-programming - Clingo/ASP:在故事生成器中生成角色的最佳方式
- javascript - 减少 - 分成多个批次
- git - 两个标签之间所有文件的 Git 统计信息
- python - 从以前的字段向 NamedTuple 添加字段
- css - 当文本长度增加时,如何阻止我的图像在 flex 容器中被推到左侧?
- pyspark - Pyspark - 数据框中的动态 where 子句
- android - 尝试检索列表时出现 Cloud Firestore 错误
- reactjs - 使用 jest typescript 模拟 Axios 的类型
- r - 当有多个因素时,如何将 TukeyHSD 结果导出到行/列中