npm package.json scripts not being called - javascript

I have the following scripts section in my projects package.json:
"scripts": {
"seed": "node bin/seed",
"test": "echo \"Error: no test specified\" && exit 1"
},
If i run $ npm test I get this:
>npm test
> node-mongo-seeds#0.0.1 test C:\Users\m089269\WebstormProjects\node-mongo-seeds
> echo "Error: no test specified" && exit 1
"Error: no test specified"
npm ERR! Test failed. See above for more details.
npm ERR! not ok code 0
If i run $ npm seed, I get this:
npm seed
Usage: npm <command>
where <command> is one of:
add-user, adduser, apihelp, author, bin, bugs, c, cache,
completion, config, ddp, dedupe, deprecate, docs, edit,
explore, faq, find, find-dupes, get, help, help-search,
home, i, info, init, install, isntall, issues, la, link,
list, ll, ln, login, ls, outdated, owner, pack, prefix,
prune, publish, r, rb, rebuild, remove, repo, restart, rm,
root, run-script, s, se, search, set, show, shrinkwrap,
star, stars, start, stop, submodule, tag, test, tst, un,
uninstall, unlink, unpublish, unstar, up, update, v,
version, view, whoami
npm <cmd> -h quick help on <cmd>
npm -l display full usage info
npm faq commonly asked questions
npm help <term> search for help on <term>
npm help npm involved overview
Specify configs in the ini-formatted file:
C:\Users\m089269\.npmrc
or on the command line via: npm <command> --key value
Config info can be viewed via: npm help config
npm#1.4.3 C:\Program Files\nodejs\node_modules\npm
Why does it recognize my test script but not my seed script?
EDIT
When I try npm run-script seed I get this error which is expected because I don't pass in a -d param:
$ npm run-script seed
> node-mongo-seeds#0.0.1 seed C:\Users\m089269\WebstormProjects\node-mongo-seeds
> node bin/seed
Populate mongo from a set of .json files.
Usage: $ node seed
Options:
-d The path to your mongo db [required]
Missing required arguments: d
npm ERR! node-mongo-seeds#0.0.1 seed: `node bin/seed`
npm ERR! Exit status 1
...
When I try npm run-script seed -d "localhost/ease" I get this error.
npm run-script seed -d localhost/ease-dev
npm info it worked if it ends with ok
npm info using npm#1.4.3
npm info using node#v0.10.26
npm ERR! Error: ENOENT, open 'C:\Users\m089269\WebstormProjects\node-mongo-seeds\node_modules\seed\package.json'
...
Why is it looking for a package.json in node_modules\seed? Seed is not even a dependency.

From the documentation:
npm supports the "scripts" member of the package.json script, for the following scripts:
prepublish: Run BEFORE the package is published. (Also run on local npm install without any arguments.)
prepare: Run both BEFORE the package is packed and published, on local npm install without any arguments, and when installing git dependencies (See below). This is run AFTER prepublish, but BEFORE prepublishOnly.
prepublishOnly: Run BEFORE the package is prepared and packed, ONLY on npm publish.
prepack: run BEFORE a tarball is packed (on npm pack, npm publish, and when installing git dependencies).
postpack: Run AFTER the tarball has been generated and moved to its final destination.
publish, postpublish: Run AFTER the package is published.
preinstall: Run BEFORE the package is installed
install, postinstall: Run AFTER the package is installed.
preuninstall, uninstall: Run BEFORE the package is uninstalled.
postuninstall: Run AFTER the package is uninstalled.
preupdate: Run BEFORE the package is updated with the update command.
update, postupdate: Run AFTER the package is updated with the update command.
pretest, test, posttest: Run by the npm test command.
prestop, stop, poststop: Run by the npm stop command.
prestart, start, poststart: Run by the npm start command.
prerestart, restart, postrestart: Run by the npm restart command. Note: npm restart will run the stop and start scripts if no restart script is provided.
Additionally, arbitrary scripts can be run by doing npm run-script <stage> <pkg>.
You can see the reason why your npm test script works is because npm test is a built-in command. You must use npm run-script if you want to execute a script that is not executed by a built-in npm command.

Custom scripts declared in the package.json can be ran with the npm run <your-script> form in your shell.
Try npm run seed or npm run test

To execute the custom scripts in package.json using below
npm run-script seed
or
npm run-script < custom script >
or you can use
npm run < custom script >

Related

When I create React app It's not creating

I am beginner in react js
I'm Create react app it's give me a error I am trying to do all the things
cmd to create app
npx create-react-app my-app or npx create-react-app#latest your-app-name --use-npm
error
npx create-react-app my-reactchat-app
npm ERR! cb() never called!
npm ERR! This is an error with npm itself. Please report this error at:
npm ERR! <https://npm.community>
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\dp312\AppData\Roaming\npm-cache\_logs\2023-01-25T22_46_04_461Z-debug.log
Install for [ 'create-react-app#latest' ] failed with code 1
I'm try to do this cmd in both mode administrator mode also
npm cache clean --force
when run this cmd
npm create-react-app my-app
it's give me error like this
Usage: npm <command>
where <command> is one of:
access, adduser, audit, bin, bugs, c, cache, ci, cit,
clean-install, clean-install-test, completion, config,
create, ddp, dedupe, deprecate, dist-tag, docs, doctor,
edit, explore, fund, get, help, help-search, hook, i, init,
install, install-ci-test, install-test, it, link, list, ln,
login, logout, ls, org, outdated, owner, pack, ping, prefix,
profile, prune, publish, rb, rebuild, repo, restart, root,
run, run-script, s, se, search, set, shrinkwrap, star,
stars, start, stop, t, team, test, token, tst, un,
uninstall, unpublish, unstar, up, update, v, version, view,
whoami
npm <command> -h quick help on <command>
npm -l display full usage info
npm help <term> search for help on <term>
npm help npm involved overview
Specify configs in the ini-formatted file:
C:\Users\dp312\.npmrc
or on the command line via: npm <command> --key value
Config info can be viewed via: npm help config
npm#6.14.15 C:\Program Files\nodejs\node_modules\npm
try to do this also but still error not soul
how to solve this error ?
anyone can help me
Define the node engines config in package.json
Also, check your node version keep it latest.
Check if you're running the app from inside of your app folder.

why show error: command failed checkout when npm install?

I clone https://github.com/mahdisadeghi74/readium-js-viewer repository but when i install npm show this error
$ npm install
npm ERR! code 1
npm ERR! Command failed: git checkout master
npm ERR! error: pathspec 'master' did not match any file(s) known to git
npm ERR!
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\M.Sadeghi\AppData\Roaming\npm-cache\_logs\2020-10-06T12_39_15_548Z-debug.log
I Use Git initialisation of this repository readme.me line by line:
git clone --recursive -b BRANCH_NAME https://github.com/readium/readium-js-viewer.git readium-js-viewer (replace "BRANCH_NAME" with e.g. "develop")
cd readium-js-viewer
git submodule update --init --recursive to ensure that the readium-js-viewer chain of dependencies is initialised (readium-js, readium-shared-js)
git checkout BRANCH_NAME && git submodule foreach --recursive "git checkout BRANCH_NAME" (or simply cd inside each repository / submodule, and manually enter the desired branch name: git checkout BRANCH_NAME) Git should automatically track the corresponding branch in the 'origin' remote.
Advanced usage (e.g. TravisCI) - the commands below automate the remote/origin tracking process (this requires a Bash-like shell):
for remote in git branch -r | grep -v \> | grep -v master; do git branch --track ${remote#origin/} $remote; done to ensure that all Git 'origin' remotes are tracked by local branches.
git checkout git for-each-ref --format="%(refname:short) %(objectname)" 'refs/heads/' | grep $(git rev-parse HEAD) | cut -d " " -f 1 to ensure that Git checks-out actual branch names (as by default Git initializes submodules to match their registered Git SHA1 commit, but in detached HEAD state)
(repeat for each repository / submodule)
Source tree preparation
npm run prepare:all (to perform required preliminary tasks, like patching code before building)
OR: yarn run prepare:yarn:all (to use Yarn instead of NPM for node_module management)
Note that in some cases, administrator rights may be needed in order to install dependencies, because of NPM-related file access permissions (the console log would clearly show the error). Should this be the case, running sudo npm run prepare:all usually solves this.
Note that the above command executes the following:
npm install (to download dependencies defined in package.json ... note that the --production option can be used to avoid downloading development dependencies, for example when testing only the pre-built build-output folder contents)
npm update (to make sure that the dependency tree is up to date)
some additional HTTP requests to the GitHub API in order to check for upstream library updates (wherever Readium uses a forked codebase)

"npm ERR! unexpected end of JSON input near" while creating a new react app

[enter image description here][1]npm
I am trying for so many times to create a app in react but every time the CMD showing an ERR!
here is code :
Microsoft Windows [Version 10.0.18363.476]
(c) 2019 Microsoft Corporation. All rights reserved.
C:\Users\Sumit>E:
The system cannot find the drive specified.
C:\Users\Sumit>D:
D:>React js
'React' is not recognized as an internal or external command,
operable program or batch file.
D:>react js
'react' is not recognized as an internal or external command,
operable program or batch file.
D:>React js
'React' is not recognized as an internal or external command,
operable program or batch file.
D:>create-react-app my_react
Creating a new React app in D:\my_react.
Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts...
npm ERR! Response timeout while trying to fetch https://registry.npmjs.org/react (over 30000ms)
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Sumit\AppData\Roaming\npm-cache_logs\2020-06-01T14_33_43_496Z-debug.log
Aborting installation.
npm install --save --save-exact --loglevel error react react-dom react-scripts has failed.
Deleting generated file... package.json
Deleting my_react / from D:\
Done.
D:>create-react-app my-react-app
Creating a new React app in D:\my-react-app.
Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts...
npm ERR! Unexpected end of JSON input while parsing near '...Y3hEcJW8se9P4K6+GYGu9'
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Sumit\AppData\Roaming\npm-cache_logs\2020-06-01T14_34_57_334Z-debug.log
Aborting installation.
npm install --save --save-exact --loglevel error react react-dom react-scripts has failed.
Deleting generated file... package.json
Deleting my-react-app / from D:\
Done.
D:>create-react-app new-react
Creating a new React app in D:\new-react.
Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts...
npm ERR! Unexpected end of JSON input while parsing near '...gAAwSQP/RpJCkm/rgw8jt'
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Sumit\AppData\Roaming\npm-cache_logs\2020-06-01T14_38_28_735Z-debug.log
Aborting installation.
npm install --save --save-exact --loglevel error react react-dom react-scripts has failed.
Deleting generated file... package.json
Deleting new-react / from D:\
Done.
D:>npm create-react-app my-react-aplication
Usage: npm
where is one of:
access, adduser, audit, bin, bugs, c, cache, ci, cit,
clean-install, clean-install-test, completion, config,
create, ddp, dedupe, deprecate, dist-tag, docs, doctor,
edit, explore, fund, get, help, help-search, hook, i, init,
install, install-ci-test, install-test, it, link, list, ln,
login, logout, ls, org, outdated, owner, pack, ping, prefix,
profile, prune, publish, rb, rebuild, repo, restart, root,
run, run-script, s, se, search, set, shrinkwrap, star,
stars, start, stop, t, team, test, token, tst, un,
uninstall, unpublish, unstar, up, update, v, version, view,
whoami
npm -h quick help on
npm -l display full usage info
npm help search for help on
npm help npm involved overview
Specify configs in the ini-formatted file:
C:\Users\Sumit.npmrc
or on the command line via: npm --key value
Config info can be viewed via: npm help config
npm#6.14.4 C:\Program Files\nodejs\node_modules\npm
D:>npx create-react-app my-react
Creating a new React app in D:\my-react.
Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts...
npm ERR! Unexpected end of JSON input while parsing near '...gAAwSQP/RpJCkm/rgw8jt'
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Sumit\AppData\Roaming\npm-cache_logs\2020-06-01T14_54_02_126Z-debug.log
Aborting installation.
npm install --save --save-exact --loglevel error react react-dom react-scripts has failed.
Deleting generated file... package.json
Deleting my-react / from D:\
Done.
D:>
if you didn't install npm in general mode, it should better you do it with this comment in the root with the command
npm install -g
, or if you did it before you need to update it with the command
npm update [-g]
There are two things that you can do that might possibily help you resolve the issue you are facing.
1.If you are on a slow internet connection you might have to increase the timeout from 30s to 60s by adding this to your .npmrc file:
timeout=6000
You can find the .npmrc file at the path:
C:\Program Files\nodejs\node_modules\npm
2. This issue might be due to npm version mismatch, you can try to install the latest npm version by typing the following command in cmd:
npm install -g npm
Hope this helps!!

Babel CLI --out-dir runs into permissions errors on second compile

I'm running into a strange error that seems to be giving me permissions issues on Windows 10. I'm using the Babel CLI to compile some ES6 code, which works great using --out-file, which will overwrite files just fine, by --out-dir doesn't. Here's the relevant parts of my package.json:
{
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-minify": "^0.2.0",
"babel-preset-env": "^1.6.0"
},
"scripts": {
"build-components": "babel Scripts/Components --out-file Scripts/Compiled/components.js",
"build-pages": "babel Scripts/Pages --out-dir Scripts/Compiled/Pages",
"watch-components": "babel Scripts/Components -w --out-file Scripts/Compiled/components.js",
"watch-pages": "babel Scripts/Pages -w --out-dir Scripts/Compiled/Pages",
"build-js": "npm run build-components && npm run build-pages"
}
}
I'm building this within Visual Studio and using the Task Runner Explorer package to run my commands (though it still fails from PowerShell, or running it as a build command within the project). The plugin runs 'npm run build-js' on build and 'npm run watch-components' and 'npm run watch-pages' afterwards to watch for any changes. 'npm run watch-pages' fails every time, as does 'npm run build-pages' if the files it outputs to already exist. The only solution I've found so far is to delete the 'Scripts/Compiled/Pages' folder every time I make a change to a file within 'Scripts/Pages', which defeats the purpose of the watch command and is generally just annoying to have to do every time, especially when I'm doing a lot of file changes. Both build commands for the components works every time and will overwrite the old file without issue.
> babel Scripts/Pages --out-dir Scripts/Compiled/Pages
Error: EPERM: operation not permitted, open 'D:\Projects\PasswordReset\Trunk\STS.PasswordReset.Web\Scripts\Compiled\Pages\Index.Vue.js'
at Error (native)
at Object.fs.openSync (fs.js:584:18)
at fs.writeFileSync (fs.js:1224:33)
at outputFileSync (D:\Projects\PasswordReset\Trunk\STS.PasswordReset.Web\node_modules\output-file-sync\index.js:45:3)
at write (D:\Projects\PasswordReset\Trunk\STS.PasswordReset.Web\node_modules\babel-cli\lib\babel\dir.js:33:5)
at handleFile (D:\Projects\PasswordReset\Trunk\STS.PasswordReset.Web\node_modules\babel-cli\lib\babel\dir.js:43:7)
at D:\Projects\PasswordReset\Trunk\STS.PasswordReset.Web\node_modules\babel-cli\lib\babel\dir.js:61:9
at Array.forEach (native)
at handle (D:\Projects\PasswordReset\Trunk\STS.PasswordReset.Web\node_modules\babel-cli\lib\babel\dir.js:59:29)
at Array.forEach (native)
npm ERR! Windows_NT 10.0.15063
npm ERR! argv "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Enterprise\\Web\\External\\Node.exe" "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Enterprise\\Web\\External\\node_modules\\npm\\bin\\npm-cli.js" "run" "build-pages" "--color=always"
npm ERR! node v5.4.1
npm ERR! npm v3.3.4
npm ERR! code ELIFECYCLE
npm ERR! STS-VueApp#1.0.0 build-pages: `babel Scripts/Pages --out-dir Scripts/Compiled/Pages`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the STS-VueApp#1.0.0 build-pages script 'babel Scripts/Pages --out-dir Scripts/Compiled/Pages'.
npm ERR! This is most likely a problem with the STS-VueApp package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! babel Scripts/Pages --out-dir Scripts/Compiled/Pages
npm ERR! You can get their info via:
npm ERR! npm owner ls STS-VueApp
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! D:\Projects\PasswordReset\Trunk\STS.PasswordReset.Web\npm-debug.log
Process terminated with code 1.
I thought maybe it was something having to do with the files not being included in my project, because I get a similar error from the component builds if my 'Scripts/Compiled' folder isn't included in the project, but including 'Scripts/Compiled/Pages' still gives me the same error and including the actual output file, ie: 'Scripts/Compiled/Pages/Index.js' doesn't fix it either.
Any ideas?? :\
It's only my thoughts. But, can you please double check:
do you run VS as Administrator?
do you run Task Runner Explorer as Administrator?
Make sure that both works under Administrator.
I'm running into something similar and the problem looks to be that babel is moving over the read only attrib on files that are under source control from VSS, i.e you pull a file from VSS it comes down with read only. The watch on it transpiles it to your target folder with read only on it. Subsequent transpiles fail as the target file won't get overwritten when it's set to read only.
I'm still working on the right solution to this but at the moment I have hacked up temp fix via a task runner command that removes read only on the entire target folder.
"babelJsxTranspileInit": "attrib -r [targetFolder] /s",

NPM rimraf - continue executing when folders are missing (stop exit code 1)

I have an npm script set up to a few synchronous commands. The starting command is npm run clean:install".
Here is the sequence:
"install:all": "npm install && bower install",
"clean": "npm run rimraf -- node_modules doc typings coverage wwwroot bower_components"
"preclean:install": "npm run clean",
"clean:install": "npm set progress=false && npm run install:all"
Works fine if all directories exist. The problem is if any of the directories are already deleted, the script exists with code 1 and prevents all additional syncronous scripts from running.
So that means it failes to run the original command of clean:install which is " "clean:install": "npm set progress=false && npm run install:all"
Error from npm:
npm ERR! angular2-webpack-starter#5.0.4 clean: `npm cache clean && npm run
rimraf -- node_modules doc typings coverage wwwroot bower_components`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the angular2-webpack-starter#5.0.4 clean script 'npm cache clean && npm run rimraf -- node_modules doc typings coverage wwwroot bower_components'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the angular2-webpack-starter package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! npm cache clean && npm run rimraf -- node_modules doc typings coverage wwwroot bower_components
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs angular2-webpack-starter
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls angular2-webpack-starter
npm ERR! There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?
The last line gives it away. It wants node_modules but can't find it so it fails.
How can I make my script continue executing to ignore these failures (missing directories)?
EDIT: The error occurs because rimraf is removing node_modules and wiping itself out. Once the folder it cleared, rimraf is gone and exit code 1. Can I exclude the rimraf folder within node_modules so it exists correctly?
I am (probably) looking at this boilerplate project you're using. Did you read the instructions? They are asking you to run npm install typings webpack-dev-server rimraf webpack -g, which includes installing rimraf globally, before even using the project. If you've failed to do this, using the npm run clean:install, or anything which calls this script, will fail because the rimraf module can't be found in your local node_modules (if already removed) or it will be deleting itself.
The solution was a bit tricky. The problem was because rimraf was removing itself since it was only installed locally in node_modules. So as soon as it removed the node_modules dir, the program died.
I realized it was necessary to add a task to have it install rimraf globally. The first task that executes is install:all. Then rimraf is in the global PATH. However, rimraf was a dependency for many other node_modules, so it kept getting installed locally and therefore ignored the global PATH. It kept dying because it was still referencing the local node_modules folder.
The trick was to uninstall rimraf locally right before executing any rimraf command. Now it's forced to use the global PATH because it doesn't exist locally.
"preinstall:all": "npm install typings webpack-dev-server rimraf webpack -g",
"install:all": "npm install && bower install",
"prerimraf": "npm uninstall rimraf",
"rimraf": "rimraf",
"clean": "npm run rimraf -- node_modules doc typings coverage wwwroot bower_components"
"preclean:install": "npm run clean",
"clean:install": "npm set progress=false && npm run install:all"
After install:all has been executed on project load (in Visual Studio 2015, Task Runner Explorer has a binding called Project Open), there are times I want to clean everything and start fresh. Now I can simply execute clean:install and uninstall node_modules and reinstall immediately with no problem! Exit code 0. Sweet!

Categories

Resources