问题描述:在用webpack做代码分割,按需加载,动态导入时,eslint检查import报错,因为eslint不支持动态导入。
报错如下图:
解决方法:
1、下载包:npm i eslint-plugin-import -D
2、在.eslintrc.js中添加如下配置:plugins: [‘import’],
rules: {
‘no-var’: 2, // 禁止使用var来声明变量
eqeqeq: [
‘warn’, // 强制使用 === 和 !==,否则警告
‘smart’, // https://eslint.bootcss.com/docs/rules/eqeqeq#smart 除了少数情况下不会有警告
],
},
plugins: [‘import’],
// 继承其他规则 继承eslint规则
extends: [‘eslint:recommended’],
【解决】Parsing error: ‘import‘ and ‘export‘ may only appear at the top level报错
于 2023-02-06 10:02:29 首次发布