JamieMason / ImageOptim-CLI

Make optimisation of images part of your automated build process
https://foldleft.io/image-tools
MIT License
3.45k stars 125 forks source link

does not work when compiling locally #172

Closed azusa-tomita closed 5 years ago

azusa-tomita commented 5 years ago

Steps To Reproduce The Error

  1. git clone https://github.com/JamieMason/ImageOptim-CLI.git.
  2. npm insatall
  3. npm pack
  4. npm install -g ./imageoptim-cli-2.3.4.tgz
  5. imageoptim ./test.png

Expected Behaviour

imageOptim.app will work and compress the image.

Actual Behaviour

Forcibly stop. The following error message is displayed.

/Users/hoge/.nvm/versions/node/v8.11.1/lib/node_modules/imageoptim-cli/dist/imageoptim:9489
        throw new TypeError(`Expected \`cwd\` to be of type \`string\` but received type \`${typeof opts.cwd}\``);
        ^

TypeError: Expected `cwd` to be of type `string` but received type `undefined`
    at module.exports.sync (/Users/hoge/.nvm/versions/node/v8.11.1/lib/node_modules/imageoptim-cli/dist/imageoptim:9489:9)
    at globDirs (/Users/hoge/.nvm/versions/node/v8.11.1/lib/node_modules/imageoptim-cli/dist/imageoptim:17316:9)
    at getPattern (/Users/hoge/.nvm/versions/node/v8.11.1/lib/node_modules/imageoptim-cli/dist/imageoptim:17319:64)
    at globTasks.reduce (/Users/hoge/.nvm/versions/node/v8.11.1/lib/node_modules/imageoptim-cli/dist/imageoptim:17365:19)
    at Array.reduce (<anonymous>)
    at Function.module.exports.sync (/Users/hoge/.nvm/versions/node/v8.11.1/lib/node_modules/imageoptim-cli/dist/imageoptim:17364:26)
    at Object.<anonymous> (/Users/hoge/.nvm/versions/node/v8.11.1/lib/node_modules/imageoptim-cli/dist/imageoptim:72:28)
    at c (/Users/hoge/.nvm/versions/node/v8.11.1/lib/node_modules/imageoptim-cli/dist/imageoptim:36190:3584)
    at Function.r.import (/Users/hoge/.nvm/versions/node/v8.11.1/lib/node_modules/imageoptim-cli/dist/imageoptim:36190:4190)
    at /Users/hoge/.nvm/versions/node/v8.11.1/lib/node_modules/imageoptim-cli/dist/imageoptim:36187:15

Version Numbers or N/A

N/A

Help Needed

JamieMason commented 5 years ago

Thanks @azusa-tomita, I've had this issue on a few projects – it needs an update to the globby dependency to fix it. I will release an update when I get some time, hopefully later today or tomorrow. In the meantime these steps should fix it for you.

  1. git clone https://github.com/JamieMason/ImageOptim-CLI.git.
  2. npm install
  3. npm install --save-dev globby
  4. npm pack
  5. npm install -g ./imageoptim-cli-2.3.4.tgz
  6. imageoptim ./test.png