Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
defeated72 opened this issue Jun 6, 2022 · 1 comment
Open

Comments

@defeated72
Copy link

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants