[英]ESLint No default export found in imported module "react"
import React, { useContext, useEffect, useRef } from 'react';
I turn on esModuleInterop
and allowSyntheticDefaultImports
in tsconfig.json
.我在
tsconfig.json
中打开esModuleInterop
和allowSyntheticDefaultImports
。
And I also use eslint-import-plugin
and eslint-import-resolver-typescript
for linting about import.我还使用
eslint-import-plugin
和eslint-import-resolver-typescript
。
But, eslint says " No default export found in imported module "react".
"但是,eslint 说“
No default export found in imported module "react".
“
How to fix this?如何解决这个问题?
{
"compilerOptions": {
"target": "esnext",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"isolatedModules": true,
"noEmit": true,
"resolveJsonModule": true,
"jsx": "react-jsx",
"jsxImportSource": "@emotion/react",
"baseUrl": "./src",
"paths": {
"@components/*": ["components/*"],
"@styles/*": ["styles/*"],
"@custom-types/*": ["custom-types/*"],
"@pages/*": ["pages/*"],
"@assets/*": ["assets/*"],
"@constants": ["constants.ts"],
"@api/*": ["api/*"],
"@context/*": ["context/*"]
},
"typeRoots": ["src/custom-types"]
},
"include": ["src"]
}
{
"env": {
"browser": true,
"es2022": true
},
"settings": {
"react": {
"version": "detect"
},
"import/resolver": {
"typescript": {
"project": "frontend/tsconfig.json"
}
}
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": "latest",
"sourceType": "module"
},
"extends": [
"plugin:jsx-a11y/recommended",
"plugin:react/recommended",
"plugin:react/jsx-runtime",
"plugin:react-hooks/recommended",
"plugin:import/recommended",
"plugin:import/typescript",
"plugin:@typescript-eslint/recommended",
"plugin:storybook/recommended",
"plugin:prettier/recommended"
],
"rules": {
"import/extensions": [
"error",
"ignorePackages",
{
"ts": "never",
"tsx": "never",
"js": "never",
"jsx": "never"
}
],
"react/prop-types": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/no-empty-interface": "off"
}
}
*
解决了我的问题。
import * as React from 'react';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.