ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

eslint遇到的报错

2022-02-17 19:31:10  阅读:470  来源: 互联网

标签:node 版本 遇到 modules js 报错 eslint https


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

标签:node,版本,遇到,modules,js,报错,eslint,https
来源: https://www.cnblogs.com/beileixinqing/p/15906066.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有