eslint遇到的報錯


eslint 和prettier ,如果有語法錯誤,都會阻止代碼自動格式化

相當於,需要你先解決掉語法錯誤之后,再自動給你格式化

配置錯誤

  • eslint Parsing error: ecmaVersion must be 3, 5, 6, or 7:

解決方案:https://stackoverflow.com/questions/62903921/how-do-i-fix-eslint-createrequire-is-not-a-function-in-atom-editor

 

  • npx eslint TypeError: Module.createRequire is not a function

解決方案:https://stackoverflow.com/questions/62903921/how-do-i-fix-eslint-createrequire-is-not-a-function-in-atom-editor

原因:我使用的node版本v10.19.0node版本過低
解決辦法:

  1. node版本升級到12以上
  2. 將 eslint 降級到版本6.8.0(7.0.0 之前的最后一個版本)。此版本仍包含createRequire.
  • Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /Users/wangping/learn/test-eslint/node_modules/@eslint/eslintrc/universal.js

require() of ES modules is not supported.

require() of /Users/wangping/learn/test-eslint/node_modules/@eslint/eslintrc/universal.js from /Users/wangping/learn/test-eslint/node_modules/eslint/lib/linter/linter.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.

Instead rename universal.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /Users/wangping/learn/test-eslint/node_modules/@eslint/eslintrc/package.json.

https://python.iitter.com/other/270726.html

原因:還是node版本

解決辦法:上個問題我改為使用了node v12.16.1 版本,根據官網(https://eslint.org/docs/user-guide/getting-started)介紹,node版本需要^12.22.0, ^14.17.0, or >=16.0.0才行。

  • npx eslint --ext .js,.vue 執行沒反應,也不報錯

原因:npx eslint . --ext .js,.vue 后綴名可加雙引號、單引號、 可不加,前面的點必須得加,不加執行沒反應,也不報錯。

 

語法錯誤

  • The body of a for in should be wrapped in an if statement to filter unwanted properties from the prototype

解決方案:

https://stackoverflow.com/questions/4166551/javascript-jslint-error-the-body-of-a-for-in-should-be-wrapped-in-an-if-statem

https://stackoverflow.com/questions/1963102/what-does-the-jslint-error-body-of-a-for-in-should-be-wrapped-in-an-if-statemen

  • Error: Failed to load parser '@babel/eslint-parser' declared in '.eslintrc.js » eslint-config-alloy » ./base.js': Cannot find module '@babel/eslint-parser'

原因:安裝了 eslint-config-alloy 之后,會報此錯誤

解決辦法: npm instasll -D @babel/eslint-parser 即可

 

 

其余eslint場景問題可參考網友文章:https://juejin.cn/post/7024760884421623822


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM