The Problem - My npx scaffolding script works fine on linux but doesn't work on windows. However I see a lot packages which runs fine on windows but I couldn't find out what they are doing differently. I asked AI tools (Chatgpt/Gemini) they couldn't provide a solution.
What happens on linux? - Script is normally executed by node and works fine.
What happens on windows? - It just opens a new command prompt window doing nothing.
- I created a npm package
@reuk/startfor scaffolding my commonly used project templates. - I intented to use it as npx script. similar to
npx create-vite. - For this i created a script and added that to the bin field in my
package.json->"bin": "./bin/cli.js". and published the package. - Running the script normally like
node ./bin/cli.jsworks perfectly fine. the only problem is when doingnpx @reuk/startit is not invoking the script using node. - My
cli.jshas a shebang#!/usr/bin/env nodeto tell the interpreter to run it using node. I know shebang only works in unix systems and windows doesn't support it, but how does create-vite work on windows, and why doesn't mine work despite having the similar code?
What am I doing wrong here? And more importantly how do I make it work cross platform seamlessly?
For reference here is the code - @reuk/start | create-vite
It seems that the name of your
binscript clashes with a cmd start command.The fix could be choosing a more specific name for the command under which you want your script to be available. This name should also be a valid filename to avoid any further issues.
In package.json:
Here is a simplified and technically imprecise explanation of what is going on when you run
npx @reuk/start:binsection inpackage.jsonand creates platform-specific wrappers undernode_modules/.binfolder. In your case, it adds files namedstartbecause another command - @reuk/start is not a valid file name.startbut it resolves to cmd command and not your script.To be honest, the last point seems to be a bug, and there are pretty many open bugs related to scoped packages in general, but I have not find any explaining this particular case.