coderaiser/minify

Can't use `require` in blank node project

bennyschmidt opened this issue · 7 comments

Does it only work with import?

Screenshot from 2022-06-19 13-37-53

Yes, only import supported.

Yes, only import supported.

Because this library is just combining other libraries, would make more sense if you made it work with the primary use case: Minifying files in a node environment when deploying, etc.

Node environment supports imports since node v12.

Why do you need require?

Node environment supports imports since node v12.

Incorrect

Why do you need require?

The same reason millions of other projects do, JavaScript isn't just React and Webpack.

Don't worry about it. The 4 other libraries you put together to make this one already have Node support so I can just use them directly

Not quite. If you read on you'll see that lists experimental support, you have to run Node with --experimental-modules and even in Node 18+ it's experimental: https://nodejs.org/api/esm.html

If you insist on allowing import only, you should use the .mjs file extension, and run with --experimental-modules, but keep in mind that this is not a default in any cloud setting like GCP or AWS where people are very likely wanting to minify code; also you get only default exports, you might want to update your usage docs.

I wonder why you wouldn't want to support something as fundamental as require.

Are you willing for a PR to build a commonjs version on publish with help of https://esbuild.github.io/ or https://github.com/swc-project/swc, for example? So both supported.

I wonder why you wouldn't want to support something as fundamental as require.

ESM is a standard that supported by Node.js, Deno and all web browsers. There is no need to put a flag --experimental-modules, everything works without it.