简体   繁体   English

babel-esLint 的问题:解析错误:ES 模块的 require()

[英]Problem with babel-esLint: Parsing error: require() of ES Module

Hello.你好。 I need your help.我需要你的帮助。 How can I fix this error?我该如何解决这个错误?

Parsing error: require() of ES Module Desktop/Projects/MealsToGo/node_modules/eslint-scope/lib/definition.js from Desktop/Projects/MealsToGo/node_modules/babel-eslint/lib/require-from-eslint.js not supported.解析错误:不支持来自 Desktop/Projects/MealsToGo/node_modules/babel-eslint/lib/require-from-eslint.js 的 ES Module Desktop/Projects/MealsToGo/node_modules/eslint-scope/lib/definition.js 的 require() . Instead change the require of definition.js in Desktop/Projects/MealsToGo/node_modules/babel-eslint/lib/require-from-eslint.js to a dynamic import() which is available in all CommonJS modules而是将 Desktop/Projects/MealsToGo/node_modules/babel-eslint/lib/require-from-eslint.js 中的 definition.js 的要求更改为在所有 CommonJS 模块中可用的动态 import()

The solution that works for me was: In the.eslintrc file Just change:对我有用的解决方案是:在 .eslintrc 文件中只需更改:

"parser": 'babel-eslint'

to:到:

"parser": '@babel/eslint-parser'

Another cause of this issue is an old node version.此问题的另一个原因是旧节点版本。

I was getting this with ESLint 8.10.0 and Node 12. Upgrading Node to 14 was the fix.我用 ESLint 8.10.0 和 Node 12 得到了这个。将 Node 升级到 14 是解决方法。

This is probably happening because you, like me, were using the old babel parser.这可能是因为您和我一样使用旧的 babel 解析器。

Just change and install or update to the lastest parser packaged in.eslintrc.js:只需更改并安装或更新到打包在 .eslintrc.js 中的最新解析器:

old.eslintrc.js: old.eslintrc.js:

module.exports = {
 parser: 'babel-eslint',
 ...
};

new.eslintrc.js新的.eslintrc.js

module.exports = {
 parser: '@babel/eslint-parser',
 ...
};

Note:笔记:

babel-eslint has been deprecated sinse Mar 2020. The package was migrated to new repo, if you want to know more i recommend you check Babel git:D babel-eslint已于 2020 年 3 月弃用。package 已迁移到新的仓库,如果您想了解更多信息,我建议您查看Babel git:D

This is the solution: module.exports = { parser: '@babel/eslint-parser', ... };这是解决方案: module.exports = { parser: '@babel/eslint-parser', ... };

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM