简体   繁体   English

Grunt 仍然无法处理 ES6 导入?

[英]Grunt still unable to handle ES6 imports?

I am working on a project under NodeJS that uses ES6 imports/exports (hence having set type: module in its package.json) and want to automate some tasks using Grunt.我正在使用 ES6 导入/导出的 NodeJS 下开发一个项目(因此在其 package.json 中设置了type: module )并希望使用 Grunt 自动化一些任务。 Now, I absolutely love grunt, but it appears to me that even in 2022 it is still not able to work nicely with ES6 modules?现在,我非常喜欢 grunt,但在我看来,即使在 2022 年,它仍然不能很好地与 ES6 模块一起工作? I always get an error saying "require() of ES Module /vagrant/Gruntfile.js from /vagrant/node_modules/grunt/lib/grunt/task.js not supported."我总是收到一条错误消息,说“不支持来自 /vagrant/node_modules/grunt/lib/grunt/task.js 的 ES 模块 /vagrant/Gruntfile.js 的 require()”。

I understand where this is coming from , and I do understand there are workaround options - in particular, renaming Gruntfile.js to Gruntfile.cjs and passing it to grunt with the --gruntfile command line option.我知道 这是从哪里来的,并且我确实知道有一些解决方法选项 - 特别是,将 Gruntfile.js 重命名为 Gruntfile.cjs 并使用--gruntfile命令行选项将其传递给 grunt。 But that is incredibly annoying - it makes the command six times as long as it would be if I could just run grunt and be done with it.但这非常烦人 - 如果我可以运行grunt并完成它,它使命令的长度是它的六倍 Pretty much the same goes for transpiling with something like Babel: That is exactly the kind of thing grunt is intended to handle in the first place, so it feels a bit like the horse riding the jockey.使用 Babel 之类的东西进行转译几乎也是如此:这正是 grunt 一开始就打算处理的事情,所以感觉有点像骑马骑马。 I feel like this should "just work".我觉得这应该“正常工作”。

Am I missing something here, or is grunt really unable to handle ES6 imports out of the box?我在这里遗漏了什么,还是 grunt 真的无法处理开箱即用的 ES6 导入?

Actually, looking at the grunt github page it appears that a recent commit has addressed it.实际上,查看grunt github 页面,似乎最近的提交已经解决了这个问题。

I guess this issue will therefore be resolved in their next update.我想这个问题将在他们的下一次更新中得到解决。

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

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