[英](ESLint/Cypress): Parsing error: ESLint was configured to run on `<tsconfigRootDir>/component/TestComponent.cy.ts` using `parserOptions.project`
I am setting up a new project with Remix (remix.run) and I am trying to configure Cypress/ESLint for component testing.我正在使用 Remix (remix.run) 设置一个新项目,并且正在尝试配置 Cypress/ESLint 以进行组件测试。 I have a
TestComponent.cy.ts
with some boilerplate code:我有一个带有一些样板代码的
TestComponent.cy.ts
:
describe('TestComponent.cy.ts', () => {
it('playground', () => {
// cy.mount()
})
})
However, the describe
function throws this Error:然而,
describe
function 抛出这个错误:
Parsing error: ESLint was configured to run on `<tsconfigRootDir>/component/TestComponent.cy.ts` using `parserOptions.project`: <tsconfigRootDir>/../../../../../../users/tduke/desktop/dev/blog/cypress/tsconfig.json
However, that TSConfig does not include this file. Either:
- Change ESLint's list of included files to not include this file
- Change that TSConfig to include this file
- Create a new TSConfig that includes this file and include it in your parserOptions.project
I have tried to reconfigure my .tsconfig.json
and .eslintrc.js
to no avail.我试图重新配置我的
.tsconfig.json
和.eslintrc.js
无济于事。 Currently, this is what those files look like:目前,这些文件是这样的:
tsconfig.json:
{
"exclude": ["./cypress", "./cypress.config.ts"],
"include": ["remix.env.d.ts", "**/*.ts", "**/*.tsx", "./cypress/component/*.cy.ts", "./cypress/**/*.cy.ts",
],
"compilerOptions": {
"lib": ["DOM", "DOM.Iterable", "ES2019"],
"types": ["vitest/globals"],
"isolatedModules": true,
"esModuleInterop": true,
"jsx": "react-jsx",
"module": "CommonJS",
"moduleResolution": "node",
"resolveJsonModule": true,
"target": "ES2019",
"strict": true,
"allowJs": true,
"forceConsistentCasingInFileNames": true,
"baseUrl": ".",
"paths": {
"~/*": ["./app/*"]
},
"skipLibCheck": true,
// Remix takes care of building everything in `remix build`.
"noEmit": true
}
}
.eslintrc.js:
/** @type {import('@types/eslint').Linter.BaseConfig} */
module.exports = {
extends: [
"@remix-run/eslint-config",
"@remix-run/eslint-config/node",
"@remix-run/eslint-config/jest-testing-library",
"prettier",
],
env: {
"cypress/globals": true,
},
parserOptions: {
project: './tsconfig.json'
},
plugins: ["cypress"],
// We're using vitest which has a very similar API to jest
// (so the linting plugins work nicely), but we have to
// set the jest version explicitly.
settings: {
jest: {
version: 28,
},
},
};
I also encountered the same problem, I solved the problem by removing the project
property under parserOptions
我也遇到了同样的问题,我通过去掉
parserOptions
下的project
属性解决了问题
parserOptions: { ecmaFeatures: { jsx: true, }, ecmaVersion: 12, sourceType: 'module', // project: 'tsconfig.json', tsconfigRootDir: __dirname, },
You should add ["./.eslintrc.js"]
to your tsconfig.json
file:您应该将
["./.eslintrc.js"]
添加到您的tsconfig.json
文件中:
{
"include": ["./.eslintrc.js"],
//...
}
This is what I ended up putting in my.eslintrc.json:这是我最终放入 my.eslintrc.json 的内容:
module.exports = {
...
parserOptions: {
parser: '@typescript-eslint/parser',
project: './tsconfig.json',
tsconfigRootDir: __dirname,
},
};
It may have been that the project needed to be ./tsconfig.json
instead of tsconfig.json
.可能是项目需要
./tsconfig.json
而不是tsconfig.json
。 My tsconfig file is in the project root.我的 tsconfig 文件在项目根目录中。
And this brought up some more errors linting things like babel config so I created an .eslintignore
file and added those in there:这带来了更多错误,例如 babel 配置,所以我创建了一个
.eslintignore
文件并在其中添加了这些文件:
.eslintrc.js
ios/
android/
*.config.js
This solved all my issues.这解决了我所有的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.