【发布时间】:2021-06-05 05:59:02
【问题描述】:
因此,我将一些“graphql”文件包含到我的组件中,但由于无法识别导入路径,它们给了我 TS 错误。一切正常,只是给出了 TS 错误。
import QUERY_GET_CATS from "@gql/GetCats.graphql";
我遇到的错误: TS2307:找不到模块“@gql/GetCat.graphql”或其对应的类型声明
这是我的 tsconfig:
{
"compilerOptions": {
"baseUrl": "src",
"paths": {
"*": [
"./*"
],
"@gql/*": [
"./api/gql/*"
]
},
"lib": ["dom", "dom.iterable", "esnext"],
"strict": true,
"noUnusedLocals": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"target": "esnext",
"module": "esnext",
"moduleResolution": "node",
"isolatedModules": true,
"jsx": "preserve",
"downlevelIteration": true,
"allowJs": true,
"skipLibCheck": true,
"resolveJsonModule": true
},
"exclude": [
"cypress",
"coverage",
"node_modules",
"build",
"dist",
"out",
".next",
"next.config.js",
"./**/*.js",
"./**/*.jsx",
"./**/*.scss"
],
"include": [
"next-env.d.ts",
"./**/*.ts",
"./**/*.tsx"
]
}
我的 eslintrc
const path = require('path');
module.exports = {
parserOptions: {
ecmaVersion: 2019,
sourceType: 'module',
project: './tsconfig.json',
ecmaFeatures: {
jsx: true,
},
},
parser: '@typescript-eslint/parser',
extends: [
'eslint:recommended',
'plugin:react-hooks/recommended',
'plugin:react/recommended',
'airbnb-typescript',
'prettier',
'prettier/react',
'eslint-config-prettier',
'eslint-config-prettier/@typescript-eslint',
'plugin:cypress/recommended'
],
globals: {
cy: true
},
rules: {
strict: ['error', 'never'],
'import/no-cycle': 0,
'import/prefer-default-export': 0,
'global-require': 0,
'react/jsx-key': 1,
'prefer-destructuring': 1,
"import/no-extraneous-dependencies": 1,
'no-console': 'warn',
'no-param-reassign': [
2,
{
props: false,
},
],
'react/prop-types': 0,
'camelcase': ['warn', {ignoreDestructuring: true, properties: 'never'}],
'react/no-unescaped-entities': 0,
'import/extensions': 'off',
'react/jsx-props-no-spreading': ['warn', {custom: 'ignore'}],
'jsx-a11y/click-events-have-key-events': 0,
'jsx-a11y/no-static-element-interactions': 0,
},
env: {
browser: true,
jest: true,
es2020: true,
'cypress/globals': true,
},
plugins: ['eslint-plugin-cypress'],
overrides: [
{
settings: {
'import/resolver': {
jest: {
jestConfigFile: path.join(__dirname, '/jest.config.js'),
},
},
},
},
],
};
注意:当我将“./**/*.graphql”添加到“include”数组时,没有帮助。 注意:我的其他别名有效。只是不是“graphql”。
【问题讨论】:
-
您的文件夹相对于 src 是如何组织的?
-
为了避免任何问题,我几乎把所有依赖这些导入的东西都放在 /src 下
标签: typescript tsconfig