Add npm install script in package.json file? - npm

"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"install": "npm install" //Creates a loop and tries to run `npm install` continuously.
},
I would like to have this script so that I can just just click on the icon/option in my IDE as shown below instead of executing npm install in the terminal to install packages.

Rename the install script to something else, like setup.

Related

I am facing "npm run dev" missing script issues. How to resolve it?

I am currently in the folder E:\Learn\app-code-vue
E:\Learn\app-code-vue>npm run dev
npm ERR! Missing script: "dev"
npm ERR!
npm ERR! To see a list of scripts, run:
npm ERR! npm run
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Shrikant Rana\AppData\Local\npm-cache\_logs\2022-01-24T14_
26_36_332Z-debug.log
See the scripts that are configured with Vue CLI 3 in the package.json file
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint" },
so you can run by use this : npm run serve
Check your package.json file and see if you have dev named in your "scripts" key. This is what your package.json script tag should look like if you want to run a dev command:
"scripts": {
"start": "node index.js",
"dev": "concurrently \"npm run server\" \"npm run client\""
},
use npm run serve
It's working for me
You may need to check if you are really in the correct folder

What is difference between "npm build", "npm run build", "npm install" and "npm run install"

What is the difference between npm build vs, npm run build and npm install vs npm run install?

Error in running nuxt project: "'nuxt' is not recognized as an internal or external command"

When I tried to run npm run dev in my nuxt project, my console returned this message:
'nuxt' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! andromeda#1.0.0 dev: `nuxt`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the andromeda#1.0.0 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
I solved this problem.
I was looking in stackoverflow for similar problems and apparently the problem was the npm cache.
I will let a link bellow with the solution and a quick sample of what i did.
Link to the answer:
npm ERR! code ELIFECYCLE
Step 1: npm cache clean --force
Step 2: Delete node_modules by $ rm -rf node_modules folder or delete
it manually by going into the directory and right-click > delete.
Delete package-lock.json file too.
Step 3: npm install
To start again, npm start
Thanks everyone who take time to help, really appreciate.
Make sure nuxt is installed in your Nuxt project:
$ cd /path/to/nuxt-project
$ npm list nuxt
nuxt-project#1.0.0 /path/to/nuxt-project
└── nuxt#2.6.3
Here /path/to/nuxt-project contains your package.json and node-modules.
If it isn't installed, add nuxt to your project by doing:
$ npm install --save nuxt
Or put it in your project's package.json then do npm install:
"dependencies": {
"nuxt": "^2.0.0"
},
UPDATE:
If you are still getting "nuxt not recognized" problems, try to use explicit path to nuxt from your node_modules directory.
Given this directory (after doing npm install --save nuxt):
nuxt-project
|- node_modules
|- .bin
|- nuxt
|- package.json
Update the dev command in package.json with:
"scripts": {
"dev": "node_modules/.bin/nuxt"
},
Sometimes this blows up because you're not exporting node_modules/.bin directory.
Place or append the following line in your .bashrc or .zshrc:
export PATH=node_modules/.bin:$PATH
Have the same problem recently.
Solution for me was change the path of scripts section in package.json from this:
"scripts": {
"dev": "nuxt",
"build": "nuxt build",
"start": "nuxt start",
"generate": "nuxt generate"
},
to that:
"scripts": {
"dev": "node_modules/.bin/nuxt",
"build": "node_modules/.bin/nuxt build",
"start": "node_modules/.bin/nuxt start",
"generate": "node_modules/.bin/nuxt generate"
},
Step 1: rm -rf node_modules package-lock.json
Step 2: npm cache clean --force
Step 3: npm install ( you may need to add --legacy-peer-deps or --force flag, if npm install is not working )
To start again, npm start
To make build, npm run build (ssr ) or generate ( csr )
Install globally cross-env:
npm install -g cross-env
Then just update package.json scripts to start with "cross-env ...."
example:
"scripts": {
"dev": "cross-env nuxt",
"build": "cross-env nuxt build",
"start": "cross-env nuxt start",
"generate": "cross-env nuxt generate",
"lint": "eslint --ext .js,.vue --ignore-path .gitignore ."
},
This works on my Windows 10.
It simply means nuxt is not installed.
Try running npm install nuxt

Difference between npm start and npm run start

I have checked both commands npm start and npm run start, both works perfectly. I used create-react-app. But to make configuration changes in the CSS module, I run npm eject but it throws an error.
But npm run eject worked? I'm confused on why npm eject didn't work. Can I configure this?
Below is my package.json:
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
npm test, npm start, npm restart, and npm stop are all aliases for npm run xxx.
For all other scripts you define, you need to use the npm run xxx syntax.
See the docs at https://docs.npmjs.com/cli/run-script for more information.
npm start is the short form for npm run start. So, its one and the same thing.
One interesting thing to note is,
If the scripts object does not have a "start" property in package.json file, npm start or npm run start from command line will run node server.js by default.
But if the scripts object in package.json has "start" property, it overrides node server.js and executes the command in "start" property.
See - https://docs.npmjs.com/cli/v7/commands/npm-start#description
Telling this because sometimes this can be help to someone.
Inside the jenkins pipelines you should use npm commands with "run"
ex- npm run start
if not the command will not be executed.

Eslint and start webpack

I would like to run eslint before webpack start.
I installed parallel and npm-run-all packages but didn't help.
When I type: npm run dev I get:
npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! myproject-ui#1.0.0
eslint: eslint src/ npm ERR! Exit status 1 npm ERR! npm ERR! Failed
at the myproject-ui#1.0.0 eslint script. npm ERR! This is probably not
a problem with npm. There is likely additional logging output above.
My package.json:
"scripts": {
"start": "node ./node_modules/webpack-dev-server/bin/webpack-dev-server.js",
"test": "mocha --compilers js:babel-core/register ./tests/**/*.js",
"test:watch": "npm run test -- --watch",
"code:coverage": "nyc npm run test",
"eslint": "eslint src/",
"dev": "npm-run-all --parallel start eslint"
},
Any idea how to run eslint and webpack parallel?;)
Greetings
It's not elegant solution but works fine
"lint": "eslint src || exit 0",
"dev": "npm-run-all --parallel lint start"
Because link returns exit 1 err so it makes them work parallel even though ;).