问题

eslint做语法检查的时候 Cannot read property ‘range’ of null

代码

λ npm run eslintfix

> dataloader@1.0.0 eslintfix E:\zyrf-git1.5\dataloaderui
> eslint --fix --ext .js,.vue src

Cannot read property 'range' of null
TypeError: Cannot read property 'range' of null
    at SourceCode.getTokenBefore (E:\zyrf-git1.5\dataloaderui\node_modules\eslint\lib\token-store\index.js:303:18)
    at checkSpacingBefore (E:\zyrf-git1.5\dataloaderui\node_modules\eslint\lib\rules\template-curly-spacing.js:52:42)
    at TemplateElement (E:\zyrf-git1.5\dataloaderui\node_modules\eslint\lib\rules\template-curly-spacing.js:117:17)
    at E:\zyrf-git1.5\dataloaderui\node_modules\eslint\lib\util\safe-emitter.js:47:58
    at Array.forEach (<anonymous>)
    at Object.emit (E:\zyrf-git1.5\dataloaderui\node_modules\eslint\lib\util\safe-emitter.js:47:38)
    at NodeEventGenerator.applySelector (E:\zyrf-git1.5\dataloaderui\node_modules\eslint\lib\util\node-event-generator.js:251:26)
    at NodeEventGenerator.applySelectors (E:\zyrf-git1.5\dataloaderui\node_modules\eslint\lib\util\node-event-generator.js:280:22)
    at NodeEventGenerator.enterNode (E:\zyrf-git1.5\dataloaderui\node_modules\eslint\lib\util\node-event-generator.js:294:14)
    at CodePathAnalyzer.enterNode (E:\zyrf-git1.5\dataloaderui\node_modules\eslint\lib\code-path-analysis\code-path-analyzer.js:608:23)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! dataloader@1.0.0 eslintfix: `eslint --fix --ext .js,.vue src`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the dataloader@1.0.0 eslintfix script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\14581\AppData\Roaming\npm-cache\_logs\2021-01-22T09_24_45_678Z-debug.log

解决

多方排查 babel-eslint 版本相对于当前的架构其他依赖包的版本来说,较高
我的版本 v 8.0.1

直接卸载,安装v 7.2.3 顺利解决

注意非动态路由问题

如果是动态路由可以切换为require方式解决

  // component: () => import(`@/views/modules/${URL}`)
  component: resolve => require([`@/views/modules/${URL}`], resolve)
Logo

前往低代码交流专区

更多推荐