我正在尝试在 es6 中导入 jsx 文件而不需要 .jsx 扩展名:
import LoginErrorDialog from './LoginErrorDialogView';
不是:
import LoginErrorDialog from './LoginErrorDialogView.jsx';
虽然我已经以这种方式成功导入了 webpack:
export default {
entry: './src/ui/js/app.js',
output: {
publicPath: '/',
filename: 'bundle.js'
},
resolve: {
extensions: ['.js', '.jsx'],
Eslint (esw webpack.config.* ./--color --ext .js --ext .jsx
) 仍然出错。
无法解析模块 './LoginView' import/no-unresolved 的路径
有什么想法吗?
最佳答案
我在这里遇到了同样的问题,我修复了在我的 .eslintrc
中添加额外的配置。
在 extends
属性中添加:
"plugin:import/react"
在settings
属性中添加:
"import/resolver": {
"node": {
"extensions": [".js",".jsx"]
}
}
您的 .eslintrc
将如下所示:
{
"extends": [
...
"plugin:import/react",
...
],
...
"settings": {
"import/resolver": {
"node": {
"extensions": [".js",".jsx"]
}
}
},
...
}
关于javascript - Eslint 错误导入没有扩展名的 jsx,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42264007/