how to run program when the start script is missing - javascript

When I am trying to run my code using npm start I am getting this error -
npm start -
npm ERR! Missing script: "start"
npm ERR!
npm ERR! Did you mean one of these?
npm ERR! npm star # Mark your favorite packages
npm ERR! npm stars # View packages marked as favorites
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\Local\npm-cache_logs\2023-01-20T08_18_49_238Z-debug-0.log

Hi you need to define the start script in the package.json file. For example here in this node project
package.json (remove the comment to use the json):
{
"name": "node-starter",
"version": "0.0.0",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js" // <-- start script here to start a node program
}
}
Full example
https://stackblitz.com/edit/node-g7ntls?file=index.js,package.json

You can use like node entry.js

Related

When I run npm run build I get this error?

I am pretty new to this and pretty lost as well. I believe I switched up a lot of things which has me facing this problem at the moment. Ultimately, I am just trying to npm run build my React.js project so I could deploy it. But I run npm run build and I see this error:
my-blog git:(main) ✗ npm run build
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /Users/rondon/code/my-blog/package.json
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, open '/Users/rondon/code/my-blog/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/rondon/.npm/_logs/2022-01-22T05_37_12_010Z-debug.log
What I understood from this is that I need to make a package.json file so I did that in my "my-blog" directory by running npm init. Cool, I do that and now I have a new package.json file in "my-blog" and I manually put in a "build": "react-scripts build" so I can run npm run build without getting an error saying I am missing a build script. This is how that package.json file looks now:
{
"name": "my-blog",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "react-scripts build"
},
"repository": {
"type": "git",
"url": "git+https://github.com/rmera1026/my-blog.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/rmera1026/my-blog/issues"
},
"homepage": "https://github.com/rmera1026/my-blog#readme"
}
I npm run build again and now get this:
my-blog git:(main) ✗ npm run build
> my-blog#1.0.0 build
> react-scripts build
sh: react-scripts: command not found
Lastly, I think I am having this problem because of how my file might be set up as well so here are how things are looking.
Your my-blog project has 2 directories. One is api, another one is client.
You have to build in your client directory, but you're outside of it. Change your directory to client and run npm run build
cd client && npm run build

poblem with use the npm start in nodejs . 'nodemon' is not recognized as an internal or external command, operable program or batch file

i create a project in ubuntu and i run and deploy that , its worked fine .
now i change the operation system and a use the windows 10 and when i run this code npm start in vscode it show me this error :
> Store#1.0.0 start F:\Projects\Nodejs\Store
> nodemon server.js
'nodemon' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! Store#1.0.0 start: `nodemon server.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the Store#1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\programmer\AppData\Roaming\npm-cache\_logs\2020-06-27T11_34_26_614Z-debug.log
i install the nodemon :
{
"name": "Store",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"start": "nodemon server.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"nodemon": "^2.0.4"
}
}
and download and install the nodejs in windows .
whats the problem ? how can i solve this problem ??
i solve the problem . i delete all node_module and install that again with npm install command .

How to continue running scripts defined in package.json in case one fails?

I have this in package.json file:
{
"name": "test demo",
"version": "1.0.0",
"description": "test demo scripts",
"scripts": {
"test:v1": "wdio src/resources/config/wdio.chrome.conf.js --spec test/Tests.spec.ts",
"test:v2": "wdio src/resources/config/wdio.firefox.conf.js --spec test/Tests.spec.ts",
"test": "npm run test:v1 && npm run test:v2"
},
...
}
When run this command:
npm run test
then if test:v1 fails, then test:v2 script is not executed at all.
Is there a way to configure this so that all scripts run regardless if some of them failed?
EDIT:
When I try this in package.json:
"test": "npm run test:v1 ; npm run test:v2"
Then I still don't get both scripts executed, just test:v1 gets executed with error.
This is what I get in the console:
C:\2020\demo>npm run test
> demo#1.0.0 test C:\2020\demo
> npm run test:v1 ; npm run test:v2
> demo#1.0.0 test:v1 C:\2020\demo
> wdio src/resources/config/wdio.chrome.conf.js --spec test/Tests.spec.ts ";"
"npm" "run" "test:v2"
Execution of 1 spec files started at 2020-06-12T15:16:42.936Z
[0-0] RUNNING in chrome - C:\2020\demo\Tests.spec.ts
... other log with failing tests ...
Spec Files: 0 passed, 1 failed, 1 total (100% completed) in 00:00:27
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! demo#1.0.0 test:v1: `wdio src/resources/config/wdio.chrome.conf.js --spec test/Tests.spec.ts ";" "npm" "run" "test:v2"`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the demo#1.0.0 test:v1 script.
npm ERR! This is probably not a problem with npm. There is likely additional
logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\<User>\AppData\Roaming\npm-cache\_logs\2020-06-
12T15_17_10_512Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! demo#1.0.0 test: `npm run test:v1 ; npm run test:v2`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the demo#1.0.0 test script.
npm ERR! This is probably not a problem with npm. There is likely additional
logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\<User>\AppData\Roaming\npm-cache\_logs\2020-06-
12T15_17_10_548Z-debug.log
If I try like this in package.json:
"test": "npm run test:v1; npm run test:v2"
Then I get this in the console:
npm ERR! missing script: test:v1;
npm ERR!
npm ERR! Did you mean one of these?
npm ERR! test:v1
npm ERR! test:v2
Thanks!
The solution for this differs depending on which OS you are using because NPM utilizes a different shell for running npm scripts.
On *nix, (Linux, macOS, etc..), the default shell that npm utilizes for running npm scripts is sh.
On Windows the default shell that npm utilizes for running npm scripts is cmd.exe.
Check which shell npm is using?
Using the npm config command you need to check the value of the script-shell setting. To do this you can run the following command:
npm config get script-shell
It will typically return/print either the pathname to cmd.exe or sh - depending on which OS your using.
Solution:
If you're running Windows and the default shell is cmd.exe
Then change your test script in package.json to the following:
"test": "npm run test:v1 & npm run test:v2"
Note the double ampersand (&&) has been replace with a single ampersand (&).
Or...
If you're running *nix and the default shell is sh
Then change your test script in package.json to the following:
"test": "npm run test:v1; npm run test:v2"
Note the double ampersand (&&) has been replace with a single semi-colon (;).
npm run test:v1; npm run test:v2
; means run the next command regardless of the success of the previous one.
&& means only run the next command if the previous one succeeded.

Node js instalation error

When i try installing node js it gives me this errors
C:\Users\Administrator>cd C:/xampp/htdocs/chat
C:\xampp\htdocs\chat>npm install
npm WARN package.json chat#4.5.0 No repository field.
npm WARN package.json chat#4.5.0 No README data
npm ERR! Windows_NT 6.1.7600
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\ node_modules\\npm\\bin\\npm-cli.js" "install"
npm ERR! node v4.5.0
npm ERR! npm v2.15.9
npm ERR! code ENOENT
npm ERR! errno ENOENT
npm ERR! syscall getaddrinfo
npm ERR! enoent getaddrinfo ENOENT registry.npmjs.org:443
npm ERR! enoent This is most likely not a problem with npm itself
npm ERR! enoent and is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! Please include the following file with any support request:
npm ERR! C:\xampp\htdocs\chat\npm-debug.log
My question is how can i prevent those errors and install node js and socket io correctly.
I suggest you install from NVM
after that. just do nvm install
to check. node -v inside your terminal
Install NodeJS from their website, then execute npm init within your project folder.
Afther that you can install dependencies from NPM.
Just read, what's on their websites under "getting started"...
I did npm init and this is my .json file
"name": "chat",
"version": "4.5.0",
"description": "IO",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Dan Vasii",
"license": "ISC",
"dependencies":
{
"socket.io" : "*",
"express" : "*"
}
}
Download the Windows installer from https://nodejs.org/en/ .
Run the installer (the .msi file you downloaded in the previous step.)
Follow the prompts in the installer (Accept the license agreement, click the NEXT button a bunch of times and accept the default installation settings).
Here is the solution for the above error.
Go to (nodejs) and Download NodeJs.
Install the NodeJs where you want in your PC
Now try to execute the command npm install
The error will be resolved. Any help needed please refer to this link

npm caching issue- did not rebuild

I'm using Laravel 5.4 with vue.js . Then i had syntax error between created and methods. I forgot , then i fix this error.
But still the error continue.
<script>
export default {
data(){
return {
users: []
}
},
created(){
this.fetchUsers();
},//forgotten
methods:{ //41.line
fetchUsers(){
this.$http.get('/users').then(response => {
this.users = response.data.users;
});
}
}
}
</script>
I was restarted apache.But still have this error if i write "npm run dev" or "npm run watch".
error in ./resources/assets/js/components/Users.vue
Syntax Error: Unexpected token, expected , (41:4)
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! # development: `cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the # development script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/ubuntu/.npm/_logs/2017-07-11T08_13_41_572Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! # dev: `npm run development`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the # dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/ubuntu/.npm/_logs/2017-07-11T08_13_41_618Z-debug.log
EDIT
I listen your advice and applied.I mean the problem is not relevant syntax mistake.The problem is old code execute insead of new code.I saved all file and then "npm run dev" but return same error everytime.
Even I got the same error- A complete log of this run can be found in:
The problem is with the port number, go to package.json file and change the port number to anything you want, say 8000. For example:
"scripts": {
"build": "webpack --config webpack.prod.js --progress",
"watch": "npm run build -- --watch",
"server": "webpack-dev-server --inline --progress --port 8000 --content-base src",
"start": "npm run server"
}
Earlier the port number was 3000, and on npm start different application use to render on port 3000 so for my new application I gave port number 8000. Now I can have two different application on different ports (localhost:3000 and localhost:8000) without getting error.

Categories

Resources