imagemin / gifsicle-bin

gifsicle bin-wrapper that makes it seamlessly available as a local dependency
http://www.lcdf.org/gifsicle/
MIT License
112 stars 52 forks source link

After Fresh Installation fail: Must use import to load ES Module #143

Open defeated72 opened 2 years ago

defeated72 commented 2 years ago

When I try to install this module, I will get an error while I try to use it.

I am using Typescript along with Node.js v14.17.5.

This is my example code:

import gifsicle from 'gifsicle'
import { execFile } from 'node:child_process'

await Promise.all([
            execFile(gifsicle, ['-o', 'output.gif', 'input.gif'], error => {
                console.log('Image minified!');
            })
])

When I run this, I get this error:

Must use import to load ES Module: C:\Projects\projects\projects\node_modules\gifsicle\index.js
require() of ES modules is not supported.
require() of C:\Projects\projects\projects\node_modules\gifsicle\index.js from C:\Projects\projects\projects\file.ts 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 index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from C:\Projects\projects\projects\node_modules\gifsicle\package.json.

I also tried renaming the files but it not worked. Removing the type: module from package.json also throws errors.

Any thoughts?

InfiniteMarcus commented 2 years ago

Did you find a solution for this problem? I'm facing the same with Typescript and Node v17