Execute npm script directly for a scoped CLI package

Executing npm run compile fails with error ‘ncli-tool missing’, though other scripts work and the CLI is installed.

{
  "scripts": {
    "compile": "ncli-tool --dest ./ui --js -- ./resources"
  }
}

I ran into a similar issue in one of my projects. After some trial and error, I discovered that the problem was often due to a conflict between a globally installed version of the CLI tool and the local one. What finally worked for me was deleting the global version and ensuring the CLI tool was correctly installed in my project’s node_modules. I also made sure that my PATH was not picking up any unintended binaries. In the end, focusing on using the local, scoped version resolved the compile error.

In my experience, the issue sometimes arises from how the scoped package is referenced in the scripts. I encountered a situation where specifying the full path to the binary in the node_modules/.bin directory improved reliability, as it ensured that the intended version was used. Modifying the script to explicitly call npx or the local binary helped prevent conflicts with any globally installed versions. This approach also allowed for a consistent environment when running scripts in various shells, thereby resolving the compilation error effectively.