ESLINT错误:'默认值'限制被用作出口名称
我在 index.js 文件中收到此 eslint 错误:
'default' 被限制用作导出名称 no-restricted-exports
page / index.js
export { default } from './test';
page / test.jsx
import React from 'react';
const Test = () => {
return <div>Test</div>;
};
export default Test;
routes.js
import React from 'react';
import { Switch, Route } from 'react-router-dom';
const testPage = React.lazy(() => import('./page'));
function Routes() {
return (
<Switch>
<Route path="/" exact component={testPage} />
</Switch>
);
}
export default Routes;
.eslintrc.json
{
"env": {
"browser": true,
"es2021": true
},
"extends": ["plugin:react/recommended", "airbnb"],
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": ["react"],
"rules": {
"import/extensions": [
"error",
"ignorePackages",
{
"js": "never",
"jsx": "never"
}
],
"react/jsx-filename-extension": [
1,
{
"extensions": [".js", ".jsx"]
}
]
},
"settings": {
"import/extensions": [".js", ".jsx"],
"import/resolver": {
"node": {
"extensions": [".js", ".jsx"]
}
}
}
}
在不禁用它的情况下解决它的正确方法是什么?
I am getting this eslint error in index.js file:
'default' is restricted from being used as an exported name no-restricted-exports
page / index.js
export { default } from './test';
page / test.jsx
import React from 'react';
const Test = () => {
return <div>Test</div>;
};
export default Test;
routes.js
import React from 'react';
import { Switch, Route } from 'react-router-dom';
const testPage = React.lazy(() => import('./page'));
function Routes() {
return (
<Switch>
<Route path="/" exact component={testPage} />
</Switch>
);
}
export default Routes;
.eslintrc.json
{
"env": {
"browser": true,
"es2021": true
},
"extends": ["plugin:react/recommended", "airbnb"],
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": ["react"],
"rules": {
"import/extensions": [
"error",
"ignorePackages",
{
"js": "never",
"jsx": "never"
}
],
"react/jsx-filename-extension": [
1,
{
"extensions": [".js", ".jsx"]
}
]
},
"settings": {
"import/extensions": [".js", ".jsx"],
"import/resolver": {
"node": {
"extensions": [".js", ".jsx"]
}
}
}
}
What would be the proper way to resolve it, without disabling that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果使用以上是一个,则您可以执行命名导入而不是这样的默认导入,
这不是错误的,但是仍在使用默认导入您默认情况下导出
test
。您可以执行此page/index.js
现在可以使用默认导入
routes.js
或根据您的路由文件
if above one is used then you've to do named import instead of default import like this
this is not wrong, but to still using the default import you've to export
test
by default. You can do thispage/index.js
now you can use default import like this
routes.js
or according to your route file
您不能导出
默认
,因为它是保留的关键字。您可以用:
You cannot export
default
because it's a reserved keyword.You could replace the line with :
在
named
和default
导出与 ESLint 规则冲突的情况下,您可以使用*
导出方法,如下所示:In situations where
named
anddefault
export is conflicting with ESLint rules, you can use*
export approach as follows: