how to solve:npm run build/dev: missing script? - npm

I'm trying to run node, but for some reason the local npm install of node isn't working.
The package is there:
$ npm run dev npm ERR! Darwin 15.4.0
npm ERR! argv "/usr/local/Cellar/node/5.6.0/bin/node" "/usr/local/bin/npm" "run" "jshint"
npm ERR! node v5.6.0
npm ERR! npm v3.6.0
npm ERR! missing script: dev
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR! <https://github.com/npm/npm/issues>
npm ERR! Please include the following file with any support request:
npm ERR! /Users/me/workspace/testapp/npm-debug.log
I can work with npm install, but run npm dev is not correct.

You saw that error because there was probably not a script named dev in the "scripts" section of your package.json
npm install and npm run dev are two completely different ideas
npm install will run through dependencies section of the package.json and fetch/install the modules in that list
npm run dev will check the scripts section of the package.json and try to find a script titled "dev" and if there is no script named "dev" it will error out as you experienced (Dev is absolutely not a special word by the way, if you ever need to use the scripts section in a future project you can name the scripts anything you want.)
As an example, make a new folder and copy the following into a file named package.json inside of it
{
"name": "testapp",
"version": "1.0.0",
"description": "",
"scripts": {
"dev": "echo This is the DEV script",
"abc": "echo This is the abc script",
"xyz": "echo This is the xyz script",
"start":"echo This is the special start script"
}
}
From your terminal, cd into the directory you made containing that sample package.json and try the following commands and see what happens:
npm run dev you should see on your screen "This is the dev script"
npm run abc you see on your scree "This is the abc script"
npm run xyz you should see on your screen "This is the xyz script"
npm run linkxu1989 you should see on your screen a similar error to what you saw above since there's no script named "linkxu1989" in the scripts part of the package.json
npm start you should see on your screen "This is the special start script" (Note that start IS a special name. You can run with just npm start or with npm run start like all the others`
Bottom line: Check the "scripts" section of package.json and to run any of them just enter npm run SCRIPT_NAME
Hope that helps and good luck w/ NPM!
See here for more details
https://docs.npmjs.com/getting-started/using-a-package.json
http://browsenpm.org/package.json (don't worry about understanding everything in it, all you should think about at this point is what's in "dependencies"
http://jsonlint.com/ (If you ever manually edit a package.json, run it through this checker to help catch any formatting mistakes. The package.json is a "json" file so it needs to be in a PERFECT format which means no trailing commas, double quotes only, etc etc)
http://www.w3schools.com/js/js_json_syntax.asp

It means in your “package.json” (in the folder in which you run “npm run build”), there’s NO “build” script. A quick check: run “npm run lalala” in your terminal/command prompt. It will show “missing script: lalala”.
So if it’s your package, add the “build” script. Just go to the package.json in your code editor and add the key value entry as JSON.
If it’s a module/package you downloaded from npmjs.org, then refer to the documentation to see what command they support.
Note: “npm build” is a completely different command from “npm run build”. All “scripts” commands except start and test need to be run with “run”.

Related

npm or yarn test fails with "npm ERR! enoent spawn bash ENOENT"

I am trying to follow a tutorial on how to fork Compound (https://medium.com/compound-finance/a-walkthrough-of-contributing-to-the-compound-protocol-9450cbe2133a). I want to add a new token. But in order to do that, I need to first be able to get the app to pass all tests.
The problem is that I can't get the tests to run in the first place. According to the tutorial, I simply need to type yarn test to run the tests. However, when I try to do this, I get error messages that seem to imply that it cannot find the path to the test file. For example:
'.\script\test' is not recognized as an internal or external command,
operable program or batch file.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command." >
or
npm ERR! code ENOENT
npm ERR! syscall spawn bash
npm ERR! path C:\Users\tombl\Documents\Code\compound-protocol
npm ERR! errno -4058
npm ERR! enoent spawn bash ENOENT
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent>
After investigating some, I discovered that it is trying to run a script in package.json called "test".
The script looks like this: "test": "./script/test",
At first, I got a response saying that "." is not a recognized command. I then tried to put the entire pathname in it so that it wouldn't have a period in it. So I edited package.json to say "test": "C:/Users/tombl/Documents/Code/compound-protocol/script/test",
That didn't work. Next, I tried to edit the environment variables in Windows so that CMD would recognize the folder (I'm using a terminal from within Visual Studio Code). That didn't work either.
After reading some other stack exchange answers, I followed the advice here (npm - The system cannot find the path specified) and typed npm config set script-shell bash. This also didn't work.
In addition, I tried editing package.json so that there is a second set of quotes in the path, like this: "test": "'C:/Users/tombl/Documents/Code/compound-protocol/script/test'", But it still didn't work.
Oh, and I tried using npm test instead of yarn test.
At this point, I have no idea what to try next.
I can see very clearly in file manager that the "test" file is there and that the path I've stated is correct. I can even open up the test file and see the code inside of it. But I can't get the terminal to run it. It just says that it isn't there.
One clue I do have is that it stops at the folder "compound-protocol". So it either doesn't recognize the folder compound-protocol at all or it doesn't recognize that the script folder is inside of it.
I've wondered if maybe the hyphen in "compound-protocol" is causing the problem, but the only advice I've gotten on how to fix that is to put the whole path in quotes, which I've already tried.
I've even tried navigating to the script folder within the terminal and running the test from there. While it does let me navigate into the script folder, trying to run the test produces a > Program 'test' failed to run: No application is associated with the specified file for this operationAt line:1 char:1. > error message.
Does anyone know how I might go about fixing this?
have you tried to use yarn install first? Also you need to use Node.js version 12 with that repository. NVM is a great tool to quickly switch between versions of Node on the command line. https://nvm.sh

What does npm run bundle do?

I'm trying to understand and follows https://github.com/DMPRoadmap/roadmap/wiki/Installation
But I don't understand something they use.
What does these do?
1) npm run bundle
I know it equals to npm run-script bundle as according to npm doc about run script but I don't really understand where the bundle come from; in other words, I don't understand what npm doc about run script mean by
an arbitrary command from a package's script object
2) npm run bundle -- -p
Since I don't know where the bundle come from, I don't know how to work out the meaning of -- -p option. I want to find its documentation and see the details.
I'm not sure if npm doc about bundle is related, but it seems to be replaced by install as documented in npm doc about install.
And why is this option got so many - characters (3 in this case) before p? I normally see 2 - for long option name and 1 - for abbreviated option name
Any time you see npm run [x] anywhere it means that it's executing a command located in the scripts section of the package.json file. Therefore npm run bundle runs the bundle command located here: https://github.com/DMPRoadmap/roadmap/blob/master/lib/assets/package.json#L8 which in this case looks like all it's doing is running webpack
"scripts": {
"test": "./node_modules/.bin/karma start",
"bundle": "./node_modules/.bin/webpack",
"lint": "./node_modules/.bin/eslint --ext .js --cache ./javascripts/ || true"
}

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
> craft#0.0.0 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...
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.
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.

npm init doesn't create package.json

I am new to ReactJS, I was following one of the tutorials in "TutorialsPoint".
In Step 2: After the folder is created we need to open it and create empty package.json file inside by running npm init from the command prompt and follow the instructions.
C:\Users\username\Desktop\reactApp>npm init
By running the above command I am unable to create and package.json
Only this thing is coming up after running init.
In Step 4: it asks to add dependencies and plugins
In Step 5: it asks to open the package.json and delete "test": "echo \"Error: no test specified\" && exit 1" inside "scripts" object.
Now how can I open package.json, if I was not been created from the beginning?
Complete the npm init prompts
The command npm init "will ask you a bunch of questions, and then write a package.json for you."
The first prompt, as shown in your screen capture, asks you to enter a package name. You can just hit Enter to skip through the prompts and accept the default values if you are unsure of what information to provide.
You can also use -y/--yes to skip the questionnaire altogether. For example, npm init -y. (Note: -f/--force also work.)
Each prompt corresponds to a field in the package.json file. Consequently, you can construct this file yourself or copy and modify an existing one from another project.
A package.json must have:
A name all lowercase one word, no spaces, dashes and underscores allowed;
A version in the form of x.x.x;
There are two ways to create a empty package.json file:
Run a CLI questionnaire to create a package.json with values that you supply. For that run the command:
npm init
Create a default package.json. For that you just need to run the same command but with the --yes or -y flag.
npm init --yes
and it will create the package.json file in the dir where you run the command and will display the code shown bellow:
{
"name": "reactApp",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}
Generally, it is not required for installing packages. If you don't use npm init for the folders, all the package can work without it.
Also for solving this problem, you should use
npm init --yes
when used with --yes then it is available the .json file in the directory. Also, the information on the .json file is dependent on the package that you had installed.
I am new on npm. I got confused just like you when i was trying to follow the npm tutorial.
You just need to press the 'Enter' key on your keyboard after your step2.
When you press 'Enter', you give default value to it. So it's gonna generate the json file based on its default information... hope it helps.
I had same problem in my project directory. when i run npm init it gives Error that package.json not found, complete log found in something like this " c:/user/node_modules/...".
This is because it overwrites the existing package.json file or the file path is not correct.
Also Admin permission is not granted to create such file. so try VS Code or IDE you all use to run as Administrator.
So, i put my project in the other Drive **(E: drive) and then run npm init** it works fine and create package.json file.
I fall onto this problem, when I typed npm init and press enter:
D:\React\booking>npm init
npm ERR! code MODULE_NOT_FOUND
npm ERR! Cannot find module './util.js'
npm ERR! Require stack:
npm ERR! - C:\Users\Sabbir\AppData\Roaming\npm\node_modules\npm\node_modules\libnpx\index.js
npm ERR! - C:\Users\Sabbir\AppData\Roaming\npm\node_modules\npm\lib\init.js
npm ERR! - C:\Users\Sabbir\AppData\Roaming\npm\node_modules\npm\lib\npm.js
npm ERR! - C:\Users\Sabbir\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Sabbir\AppData\Roaming\npm-cache\_logs\2020-07-13T05_58_52_734Z-debug.log
Here is the answer that helps a lot about this problem
Follow these steps, closely:
http://nodejs.org/download/ download the 64 bits version, 32 is for hipsters
Install it anywhere you want, by default: C:\Program Files\nodejs
Control Panel -> System -> Advanced system settings -> Environment Variables
Select PATH and choose to edit it.
If the PATH variable is empty, change it to this: C:\Users{YOUR USERNAME HERE}\AppData\Roaming\npm;C:\Program Files\nodejs
If the PATH variable already contains C:\Users{YOUR USERNAME HERE}\AppData\Roaming\npm, append the following right after: ;C:\Program Files\nodejs
If the PATH variable contains information, but nothing regarding npm, append this to the end of the PATH: ;C:\Users{YOUR USERNAME HERE}\AppData\Roaming\npm;C:\Program Files\nodejs
Now that the PATH variable is set correctly, you will still encounter errors. Manually go into the AppData directory and you will find that there is no npm directory inside Roaming. Manually create this directory.
Re-start the command prompt and npm will now work.
Installing Node.js (and npm) on Windows 10

How do I run an npm script of a dependent package

I have a package that itself has a script in its package.json that I would like to be able to run in my top-level project. This package is one of my top-level projects dependencies. I'm looking for a way to directly or indirectly call the dependency packages script.
Let us assume the module name I'm working with is named foo and the script I want to run is updateFooData.
I tried using the syntax npm run-script <package> <...> to run it, but this appears to be deprecated functionality as I can't find it in the current official documentation but I see it in other (very old) search results.
npm run-script foo updateFooData
# npm ERR! missing script: foo
I also looked into the npm api and while npm.commands.run-script(args, callback) will do what I want, I can't figure out how to load the module into npm
{
...
"scripts":{
"foo:updateFooData": "node --eval \"... ??; npm.commands.run-script('updateFooData', callback)\""
}
}
npm run foo:updateFooData
# Obviously fails
The only thing I've found that works so far is to CD into the submodule directory and run npm from there. This is not the preferred solution for me.
cd node_modules/foo
npm run updateFooData
I ran into this trying to run the updatedb script for geoip-lite. You should use the npm explore command which will spawn a new shell in a dependencies' directory.
So for your use case, try npm explore foo -- npm run updateFooData
Note:
This isn't a very good idea. You have no guarantee which node_modules folder module will be installed in as NPM will attempt to optimise space by installing shared packages at the highest level possible. – #superluminary
Something I've found that does work:
If the script you are running runs a script file, you can look at the path of the file it's running and run the script using a require:
# if node_modules/foo/package.json looks like this
{
"scripts": {
"updateFooData":"scripts/updateFooData.js"
}
}
# then package.json can look like this
{
"scripts": {
"foo:updateFooData":"node --eval \"require('foo/scripts/updateFooData.js')\""
}
}
# or package.json can look like this
{
"scripts": {
"foo:updateFooData":"node node_modules/foo/scripts/updateFooData.js"
}
}
# and you can run it like this
npm run foo:updateFooData
I don't like this solution because it only works if the npm script you are running is a file. It won't apply in all