funbox / optimizt

CLI image optimization tool

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to customize input and output directory on Windows

ClydeDz opened this issue · comments

Hi,
I installed and ran the command that's mentioned in the documentation but I'm getting this error. Could you please help?

> optimizt --verbose --force --avif --webp .

Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only URLs with a scheme in: file and data are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'd:'
    at new NodeError (node:internal/errors:399:5)
    at throwIfUnsupportedURLScheme (node:internal/modules/esm/resolve:1059:11)
    at defaultResolve (node:internal/modules/esm/resolve:1135:3)
    at nextResolve (node:internal/modules/esm/loader:163:28)
    at ESMLoader.resolve (node:internal/modules/esm/loader:838:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
    at ESMLoader.import (node:internal/modules/esm/loader:525:22)
    at importModuleDynamically (node:internal/modules/esm/translators:110:35)
    at importModuleDynamicallyCallback (node:internal/process/esm_loader:35:14)
    at optimizt (file:///D:/Code/webapi-monorepo-poc/images/node_modules/@funboxteam/optimizt/index.js:11:22) {
  code: 'ERR_UNSUPPORTED_ESM_URL_SCHEME'
}

I also tried specifying input and output directories, but I get the same error as mentioned above.
I'm using Windows 11, trying this using VS Code PowerShell terminal.
Thanks!

I also came across this error on Windows.

The problem (and solution) seems to be in index.js line 11. Instead of:

  const configData = await import(configFilepath);

... this needs to be:

  const configData = await import(pathToFileURL(configFilepath));

(with import { pathToFileURL } from 'node:url';)

The bug has been fixed in v5.0.1. Feel free to reopen this issue, if the fix does not work for you.

Thanks!