sindresorhus / gulp-filter

Filter files in a `vinyl` stream
MIT License
315 stars 37 forks source link

Q: How to use this ESM-only package? #97

Closed marekdedic closed 10 months ago

marekdedic commented 10 months ago

Hi, I am trying to upgrade to v8, however, I am at a loss as to how to use this package... I have read the linked gist and I am on node 20, so I think I have all the prerequisites ready... However, given that this is a gulp plugin, I am a bit lost when it comes to the state of ESM in gulpfiles...

1) If I keep const filter = require("gulp-filter");, I get Error [ERR_REQUIRE_ESM]: require() of ES Module... 2) If I switch it to const filter = await import("gulp-filter");, I get SyntaxError: await is only valid in async functions and the top level bodies of modules 3) If I switch to import filter from "gulp-filter";, I get SyntaxError: Cannot use import statement outside a module. This happens even when I convert all import to this style...

So it seems to me like gulpfiles cannot use ESM? If that's the case, does that mean v8 is unusable without a preprocessor like ts-node?

sindresorhus commented 10 months ago

This has nothing to do with this package specifically. This package has the correct ESM config.

https://gist.github.com/noraj/007a943dc781dc8dd3198a29205bae04

marekdedic commented 10 months ago

Great, that doc is exactly what I needed, thanks!

I suggest maybe adding a link to it to the v8 release? I think it applies here maybe more than the one linked currently...