Nate Anderson
Nate Anderson

Reputation: 21074

npm run cannot run an script found in node_modules/.bin/___

I installed sequelize-cli:

npm install sequelize-cli --save

I have only installed it locally, not globally. My local project is at C:/git/craft

I try to execute it by typing sequelize-cli, but this doesn't work; I forget I must type node_modules/.bin/sequelize-cli

I want to use npm run sequelize-cli, expecting this will be a shortcut. The npm-run-script documentation says:

In addition to the shell's pre-existing PATH, npm run adds node_modules/.bin to the PATH provided to scripts. Any binaries provided by locally-installed dependencies can be used without the node_modules/.bin prefix

And yet, when I try to run the script:

  "scripts": {
      "sequelize-cli":"sequelize-cli"
    },

The result fails:

NND@usrem-nnd MINGW64 /c/git/craft (master)
$ npm run sequelize-cli -- --help

> [email protected] sequelize-cli C:\git\craft
> sequelize-cli "--help"

'sequelize-cli' is not recognized as an internal or external command,
operable program or batch file.

npm ERR! Windows_NT 10.0.16299
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "sequelize-cli" "--" "--help"

I couldn't find similar questions/issues online (specifically re: node_modules/.bin/____)

Some Github issues mention that yarn should work, (but also say that npm should work as I expect!.) As a workaround I will just install sequelize-cli globally. I can install sequelize-cli globally, but then running sequelize-cli still produces "command not found". This led me to see my silly mistake...

Upvotes: 2

Views: 2332

Answers (2)

Nate Anderson
Nate Anderson

Reputation: 21074

Ensure you are referencing a script that exists! I wasn't! In fact, npm run was just revealing the obvious problem: the script sequelize-cli doesnt exist anywhere on the computer!

... The script is called sequelize, even though it comes from a project called sequelize-cli. package.json "scripts" value will determine which scripts can be run; the correct package.json should map the script "sequelize" to the nodejs command sequelize:

  "scripts": {
      "start": "node ./bin/www",
      "sequelize":"sequelize"
    },

npm run sequelize now works...

My mistake... this answer can be deleted if it's unhelpful.

Upvotes: 1

donglai yang
donglai yang

Reputation: 36

I had the same question as you. You may have the same problem

Finally, I found it's caused by my project folder has invalid letter.

Change your project folder name and try again.

Upvotes: 2

Related Questions