Why can't npm start? - node.js

I got a new notebook, so I install all languages I use. I use nodejs v10.16.
I had an Angular code which I wanted to run on the new notebook. The version of the node was the same. However, when I wrote in the command line npm start, I got these message:
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! <my-project>-client#0.0.0 start: `ng serve`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the <my-project>-client#0.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Why did it happend? I install node_modules before starting and it ran on my earlier notebook.
How should I solve this problem?

Make sure you're running the start script from the same location as your package.json file.
Check the format of package.json scripts object, ensuring the script name is correct and denoting where the script/object ends with a comma.
"scripts": {
"start": "react-scripts start"
},
Ensure the app/module your start script is calling is installed/installed correctly.
Use the full npm command to run your start script:
npm run start
If all else fails, rename your node_modules to node_modules_old, check your package.json file has all your required dependencies and run npm install from the same directory to generate a new node_modules folder before trying to run the script again with npm run start.

Related

npm start command returns an error in the cmd

I want to start my React app, but when I run npm start, I get this error:
npm ERR! syscall open
npm ERR! path C:\Users\Muchendu\Documents\GitHub\Steve-React/package.json
npm ERR! errno -4058
npm ERR! enoent ENOENT: no such file or directory, open 'C:\Users\Muchendu\Documents\GitHub\Steve-React\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! C:\Users\Muchendu\AppData\Local\npm-cache\_logs\2022-05-11T09_26_37_201Z-debug-0.log
This could be because right after running
npx create-react-app <your_app_name>
you are trying to run npm start
Instead try switching into your app directory like so:
cd <your_app_name>
because that is where your package.json will most likely exist and then try running
npm start
run this command in the terminal inside your project npm init -y.
This will generate a package.json in your project.
Otherwise since you are making a react app use the npx create-react-app your-app-name this will create all the necessary files for running you application.
What is package.json?
The package.json file is the heart of any Node project. It records important metadata about a project which is required before publishing to NPM, and also defines functional attributes of a project that npm uses to install dependencies, run scripts, and identify the entry point to our package.

Issue while executing " npm start" command

I am working on Frontend side Project. I create React_app and after that I run the 'npm start' command it returns an error. The error is as follows.
(hello) D:\NewPython\DockerDjangoReactProject\frontend\react_app>npm start
> react_app#0.1.0 start D:\NewPython\DockerDjangoReactProject\frontend\react_app
> react-scripts start
'react-scripts' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! react_app#0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the react_app#0.1.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\User\AppData\Roaming\npm-cache\_logs\2020-12-01T05_06_13_740Z-debug.log
please help me solve this problem, I want to complete my project but this error is in my way.
This issue is with react-scripts. Possibilities are
react-scripts is not installed. In this case, you can manually install using this command.
npm install react-scripts --save
Or if it is already there, then it might be the problem with node_modules folder. You can remove this folder and/or run the following command.
npm install

react scripts not found

I have a problem running npm start from my newly created project, the thing is the problem doesn't seem to occur outside of this folder (its a git repo, so it needs to be in here). If i create a new project in another folder and run npm start I have no issues at all.
So I recently started working in Ubuntu 18.04LTS, gone through all the setup of installing nodejs and npm.
Currently running versions:
node = 10.16.0
npm = 6.9.2
So I created my app by using npx create-react-app
When i run npm start inside this, it throws me an error:
sh: 1: react-scripts: not found
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! frontend#0.1.0 start: `react-scripts start`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the frontend#0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely
additional logging output above.
I tried create the app in another folder, testing if i can run npm start (yes) and the move this app to my repo, but then it fails again.
If i understand well what you wrote, "npm start" worked fine when you changed folders. If this is the case, you should know that Node has issues reading the path when some particular characters (like "&") or spaces are in the name of a folder.
Try to change the folder's name.

I am having this ERR! code ELIFECYCLE error while running npm start locally?

I am newbie to React and trying to build my first React App. My App was running fine till last night. When I open my project in the morning and ran npm start or yarn start command, it gave me error - ERR! code ELIFECYCLE
I tried to close app and tried to run command again as per one of the solution given in the forum. But, that didn't work.
" *react-scripts start
'react-scripts' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! my-portfolio#0.1.0 start: react-scripts start
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the my-portfolio#0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely
additional logging output above.
"*
Thank you in advance!
You're missing the react-scripts package. You need to do an npm install.
If npm install doesn't fix your problem it's probably because npm install is not able to properly complete the installation. Try this instead:
Delete the node_modules folder and
delete the package-lock.json file or the yarn.lock file
Run npm install
Run npm i -S react-scripts
Run npm start
Good luck!

Setting up a task in package.json

I am trying to setup a task in package.json
"scripts": {
"unit-test": "mocha './test/unit/**/*.spec.js'",
}
However when I run
npm run unit-test
the following errors are thrown in the console at the end of the run:
npm ERR! Darwin 16.6.0
npm ERR! argv "/Users/shreya.vakil/.nvm/v6.9.5/bin/node" "/Users/d.bubble/.nvm/v6.9.5/bin/npm" "run" "unit-test"
npm ERR! node v6.9.5
npm ERR! npm v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! myapp#0.0.1-SNAPSHOT unit-test: `mocha './test/unit/**/*.spec.js'`
npm ERR! Exit status 1
However, if I change the command to
"scripts" : {
"unit-test": "mocha './test/unit/**/*.spec.js'; exit 0",
}
this error is not thrown. However, I am not sure if this is the right approach.
The original behavior is correct, if a little ugly - if your tests fail, Mocha returns an exit code of 1, which is technically an error. Your second example makes the output prettier, but it'll cause you issues if you try to integrate your build scripts into other tools (for example, Travis), as they won't be able to detect when your tests fail.
The best solution to this would be to get rid of the exit 0 and upgrade your version of NPM - the output was made much shorter in v4.6.1. You can do this by running the following command:
npm install npm -g

Resources