on giving npm start in command prompt in react js - node.js

I am getting the below error every time in my command prompt basically I am unable to open my server because of the start in package.json is throwing the error, i am not able to find what issue is, please advice what is the correct way
Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Users\user>d:
D:>cd reactApp
D:\reactApp>npm install -g npm#latest
C:\Users\user\AppData\Roaming\npm\npm -> C:\Users\user\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js
C:\Users\user\AppData\Roaming\npm\npx -> C:\Users\user\AppData\Roaming\npm\node_modules\npm\bin\npx-cli.js
+ npm#5.8.0
added 523 packages in 116.024s
D:\reactApp>rm -rf node_modules
'rm' is not recognized as an internal or external command,
operable program or batch file.
D:\reactApp>npm -rf node_modules
Usage: npm <command>
where <command> is one of:
access, adduser, bin, bugs, c, cache, ci, completion,
config, ddp, dedupe, deprecate, dist-tag, docs, doctor,
edit, explore, get, help, help-search, i, init, install,
install-test, it, link, list, ln, login, logout, ls,
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\user\.npmrc
or on the command line via: npm <command> --key value
Config info can be viewed via: npm help config
npm#5.8.0 C:\Users\user\AppData\Roaming\npm\node_modules\npm
D:\reactApp>npm install
npm WARN babel-loader#7.1.4 requires a peer of babel-core#6 but none is installed. You must install peer dependencies yourself.
npm WARN reactapp#1.0.0 No repository field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents#1.1.3 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents#1.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
removed 10 packages in 21.906s
D:\reactApp>npm start
> reactapp#1.0.0 start D:\reactApp
> npm run build
> reactapp#1.0.0 build D:\reactApp
> webpack -d && cp src/index.html dist/index.html && webpack-dev-server --content-base src/ --inline --hot
The CLI moved into a separate package: webpack-cli.
Please install 'webpack-cli' in addition to webpack itself to use the CLI.
-> When using npm: npm install webpack-cli -D
-> When using yarn: yarn add webpack-cli -D
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! reactapp#1.0.0 build: `webpack -d && cp src/index.html dist/index.html && webpack-dev-server --content-base src/ --inline --hot`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the reactapp#1.0.0 build 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\2018-03-27T03_57_54_881Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! reactapp#1.0.0 start: `npm run build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the reactapp#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\user\AppData\Roaming\npm-cache\_logs\2018-03-27T03_57_54_983Z-debug.log
D:\reactApp>npm install -g react-scripts
C:\Users\user\AppData\Roaming\npm\react-scripts -> C:\Users\user\AppData\Roaming\npm\node_modules\react-scripts\bin\react-scripts.js
> uglifyjs-webpack-plugin#0.4.6 postinstall C:\Users\user\AppData\Roaming\npm\node_modules\react-scripts\node_modules\uglifyjs-webpack-plugin
> node lib/post_install.js
npm WARN ajv-keywords#3.1.0 requires a peer of ajv#^6.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents#1.1.3 (node_modules\react-scripts\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents#1.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
+ react-scripts#1.1.1
added 1324 packages from 785 contributors in 453.077s
D:\reactApp>npm start
> reactapp#1.0.0 start D:\reactApp
> npm run build
> reactapp#1.0.0 build D:\reactApp
> webpack -d && cp src/index.html dist/index.html && webpack-dev-server --content-base src/ --inline --hot
The CLI moved into a separate package: webpack-cli.
Please install 'webpack-cli' in addition to webpack itself to use the CLI.
-> When using npm: npm install webpack-cli -D
-> When using yarn: yarn add webpack-cli -D
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! reactapp#1.0.0 build: `webpack -d && cp src/index.html dist/index.html && webpack-dev-server --content-base src/ --inline --hot`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the reactapp#1.0.0 build 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\2018-03-27T04_06_58_572Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! reactapp#1.0.0 start: `npm run build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the reactapp#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\user\AppData\Roaming\npm-cache\_logs\2018-03-27T04_06_58_697Z-debug.log
D:\reactApp>npm start
my package.json file is
{
"name": "reactapp",
"version": "1.0.0",
"description": "some basics reactjs",
"main": "index.js",
"scripts": {
"start": "npm run build",
"build": "webpack -d && cp src/index.html dist/index.html && webpack-dev-server --content-base src/ --inline --hot",
"build:prod": "webpack -p && cp src/index.html dist/index.html"
},
"keywords": [
"reactjs"
],
"author": "Harsh mewari",
"license": "ISC",
"dependencies": {
"react": "^16.2.0",
"react-dom": "^16.2.0"
},
"devDependencies": {
"babel-loader": "^7.1.4",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-2": "^6.24.1",
"webpack": "^4.2.0",
"webpack-dev-server": "^3.1.1"
}
}
my webpack.config.js file is
var path=require("path");
var DIST_DIR = path.resolve(dirname,"dist");
var SRC_DIR= path.resolve(_dirname,"src");
var config={
entry: SRC_DIR + "/app/index.js",
output:{
path: DIST_DIR + "/app",
filename:"bundle.js",
publicPath:"/app"
},
modules:{
loaders:[
{
test:/\.js?/,
include: SRC_DIR,
loader:"babel-loader",
query:{
presets:["react","es2015","stage-2"]
}
}
]
};
module.exports= config;
}

Related

Posting to cyclic and it's asking for package.json to be in the root?

package.json not found at root level of repository.
Cyclic runs scripts defined "scripts" section to build, test and run your app.
But my project is set up like:
-final
--backend
---package.json(including npm start)
--frontend
---package.json(including npm start)
-package.json
^ includes:
"scripts": {
"frontend": "cd frontend; npm start",
"backend": "cd backend; npm start"
How do I merge these packages together and put them into the root directory so I can make this react application live?
I was thinking about something like this:
"scripts": {
"frontend": "cd frontend; npm start",
"backend": "cd backend; npm start"
but when I go to the root directory (final)
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

Facing issues with npm i and installing npm packages

Hi I'm trying to install NPM package via NPM I, however I constantly get this error:
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: cypress-image-snapshot#4.0.1
npm ERR! Found: cypress#9.6.0
npm ERR! node_modules/cypress
npm ERR! dev cypress#"9.6.0" from the root project
npm ERR! peer cypress#"*" from #cypress/code-coverage#3.9.12
npm ERR! node_modules/#cypress/code-coverage
npm ERR! dev #cypress/code-coverage#"^3.9.12" from the root project
npm ERR! 2 more (#cypress/react, cypress-expect)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer cypress#"^4.5.0" from cypress-image-snapshot#4.0.1
npm ERR! node_modules/cypress-image-snapshot
npm ERR! dev cypress-image-snapshot#"^4.0.1" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: cypress#4.12.1
npm ERR! node_modules/cypress
npm ERR! peer cypress#"^4.5.0" from cypress-image-snapshot#4.0.1
npm ERR! node_modules/cypress-image-snapshot
npm ERR! dev cypress-image-snapshot#"^4.0.1" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR! See /Users/USER/.npm/eresolve-report.txt for a full report.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/USER/.npm/_logs/2022-04-29T10_17_53_835Z-debug-0.log
This is my package.json file:
{
"scripts": {
"cy:run": "cypress run",
"cy:open": "cypress open"
},
"devDependencies": {
"#cypress/code-coverage": "^3.9.12",
"cypress": "9.6.0",
"cypress-expect": "^2.5.2",
"cypress-image-snapshot": "^4.0.1"
},
"dependencies": {
"#cypress/react": "^5.12.4",
"#cypress/vite-dev-server": "^2.2.2",
"webpack-dev-server": "^4.8.1"
},
"engines": {
"node": ">=18.0.0"
}
}
Not sure what the problem is exactly, but everytime i try to install a package or just purely run npm i, I get the above error, would appreciate it if someone can help?
if there is any issue in running npm install , try to run yarn install command to find which package has problem or dependency,yarn install command will give clear idea to the developer on issue's for installing , you can find them in the warnings as below
warning " > #cypress/react#5.12.5" has unmet peer dependency
"react#^=16.x || ^=17.x". warning " > #cypress/react#5.12.5" has unmet
peer dependency "react-dom#^=16.x || ^=17.x". warning " >
#cypress/vite-dev-server#2.2.3" has unmet peer dependency "vite#>=
2.1.3". warning " > webpack-dev-server#4.9.3" has unmet peer dependency "webpack#^4.37.0 || ^5.0.0". warning "webpack-dev-server >
webpack-dev-middleware#5.3.3" has unmet peer dependency
"webpack#^4.0.0 || ^5.0.0".
use below configuration to resolve the above issue
"scripts": {
"cy:run": "cypress run",
"cy:open": "cypress open"
},
"devDependencies": {
"#cypress/webpack-dev-server": "^2.0.0",
"#cypress/react": "^6.0.0",
"#types/cypress-image-snapshot": "^3.1.4",
"#cypress/code-coverage": "^3.9.12",
"cypress": "^9.6.0",
"cypress-expect": "^2.5.2"
},
"dependencies": {
"#cypress/vite-dev-server": "^2.2.2"
},
"engines": {
"node": ">=18.0.0"
}
The issue might be related to the peerDependencies of the cypress-image-snapshot package.
The peerDependencies look like:
"peerDependencies": {
"cypress": "^4.5.0"
}
But at the moment of writing this response the current version of cypress is 12.2.0 --> https://github.com/cypress-io/cypress/releases
It seems that cypress-image-snapshot need to update the peerDependencies.
I found this issue that is similar to the problem that you are having. Also, the last time the library was updated was on Jan 222.
A workaround could be running npm install --legacy-peer-deps although this doesn't fix the real issue.
Can you override the peer dependency in the package-lock?
"overrides": {
"cypress-image-snapshot" : {
"cypress": "$cypress"
}
}

npm - Issue to force npm run jasmine from local node_modules

I installed jasmine npm module as global. Later on, with the purpose of sharing code and make easy for the team to have all dependencies, I installed jasmine locally to the project using --save-dev.
Issue is that it tries to exec from node_modules global one instead of local one.
Package.json
{
"name": "tdd",
"version": "1.0.0",
"description": "testing tdd practices",
"main": "index.js",
"scripts": {
"test": "$(npm bin)/jasmine"
},
"keywords": [
"test",
"tdd",
"jasmine",
"node"
],
"license": "ISC",
"devDependencies": {
"jasmine": "^2.4.1"
}
}
If my tests are passing I get no errors. In case a test does not pass, I get an error pointing to the global node_modules.
Albertos-MBP:TDD albertof$ npm run test
> tdd#1.0.0 test /Users/albertof/Projects/Web/TDD
> jasmine
Started
......FF
Failures:
1) Html Replacement Regex: should replace . in src attributes for <img src="./hello.jpg">
Message:
Expected '<img static/hello.jpg">' to be '<img src="static/hello.jpg">'.
Stack:
Error: Expected '<img static/hello.jpg">' to be '<img src="static/hello.jpg">'.
at Object.<anonymous> (/Users/albertof/Projects/Web/TDD/spec/htmlSpec.js:22:62)
8 specs, 1 failures
Finished in 0.015 seconds
npm ERR! Darwin 15.5.0
npm ERR! argv "/usr/local/bin/node" "/Users/albertof/npm-global/bin/npm" "run" "test"
npm ERR! node v6.0.0
npm ERR! npm v3.8.8
npm ERR! code ELIFECYCLE
npm ERR! tdd#1.0.0 test: `jasmine`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the tdd#1.0.0 test script 'jasmine'.
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 tdd package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! jasmine
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs tdd
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls tdd
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /Users/albertof/Projects/Web/TDD/npm-debug.log
What is the reason to try to execute from the global node_modules installed?
Running npm bin return the local one for the current project /Users/albertof/Projects/Web/TDD/node_modules/.bin
edit your package.json
"scripts": {
"test": "$(npm bin)/jasmine; exit 0"
}

How to unlink a npm command-line tool?

I use node to write a command-line tool.
this is the index.js.
#!/usr/bin/env node
console.log('qiuyuntao');
this is the package.json
{
"name": "qiu",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"bin": {
"qyt": "index.js"
}
}
After I use command npm link, I can use command qyt anywhere. Now I want to unlink the command, I use npm unlink, it said
npm ERR! gentlyRm containing path /usr/local/lib/node_modules/qiu isn't under npm's control
npm WARN install:qiu#1.0.0 Refusing to delete: /usr/local/bin/qyt not in /usr/local/lib/node_modules/qiu
- qiu#1.0.0 node_modules/qiu
So, what should I do to unlink it?
Without knowing what version of npm you are using and if this is a bug thats being resolved I suspect that your global prefix is misconfigured perhaps.
At any rate the easiest solution is to manually remove the symlinks /usr/local/bin/qyt and /usr/local/lib/node_modules/qiu. If you are using the latest version of npm look into filing an issue, otherwise update (npm i -g npm).
Updating npm 3.9.5 > 4.0.5 fixed the same issue for me
Before update:
$ npm unlink
npm WARN install:#coolman/my-module#1.0.0 Refusing to delete /Users/coolman/.nvm/versions/node/v6.2.0/bin/mymod: ../lib/node_modules/my-module/index-cli.js symlink target is not controlled by npm /Users/coolman/.nvm/versions/node/v6.2.0/lib/node_modules/#coolman/my-module
- #coolman/my-module#1.0.0 node_modules/#coolman/my-module
$ npm --version
3.9.5
After update:
$ sudo npm install npm#latest -g
$ npm --version
4.0.5
$ npm unlink
- #coolman/my-module#1.0.0 node_modules/#coolman/my-module
And to repeat npm link, I needed to manually remove the bin:
$ npm link
npm WARN #my-company/my-module#1.0.0 No repository field.
npm ERR! Darwin 16.1.0
npm ERR! argv "/Users/coolman/.nvm/versions/node/v6.2.0/bin/node" "/Users/coolman/.nvm/versions/node/v6.2.0/bin/npm" "link"
npm ERR! node v6.2.0
npm ERR! npm v4.0.5
npm ERR! path /Users/coolman/.nvm/versions/node/v6.2.0/bin/mymod
npm ERR! code EEXIST
npm ERR! Refusing to delete /Users/coolman/.nvm/versions/node/v6.2.0/bin/mymod: ../lib/node_modules/my-module/index-cli.js symlink target is not controlled by npm /Users/coolman/my-company/tools/my-module
npm ERR! File exists: /Users/coolman/.nvm/versions/node/v6.2.0/bin/mymod
npm ERR! Move it away, and try again.
npm ERR! Please include the following file with any support request:
npm ERR! /Users/coolman/my-company/tools/my-module/npm-debug.log
$ rm /Users/coolman/.nvm/versions/node/v6.2.0/bin/mymod
$ npm link
npm WARN #coolman/my-module#1.0.0 No repository field.
/Users/coolman/.nvm/versions/node/v6.2.0/bin/mymod -> /Users/coolman/.nvm/versions/node/v6.2.0/lib/node_modules/#coolman/my-module/index-cli.js
/Users/coolman/.nvm/versions/node/v6.2.0/lib/node_modules/#coolman/my-module -> /Users/coolman/perkbox/tools/run-with-pb-session

Npm errors while I try to install dependencies in loopback (strongloop) webapp

I am new in the NodeJS world. I have created an loopback(strongloop) webapp, but after it I try to run the npm install command in the application's folder I get this output in the terminal (Ubuntu server 14.04 withd newest updates - in a vagrant instance)
vagrant#vagrant-ubuntu-trusty-64:/vagrant/example-app$ npm install
npm WARN package.json example-app#1.0.0 No license field.
npm WARN optional dep failed, continuing ycssmin#1.0.1
npm WARN deprecated jsonstream#1.0.3: use JSONStream instead
npm WARN optional dep failed, continuing request#2.62.0
npm WARN optional dep failed, continuing loopback-explorer#1.8.0
npm ERR! Linux 3.13.0-62-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "install"
npm ERR! node v4.1.0
npm ERR! npm v2.14.3
npm ERR! path ../node-uuid/bin/uuid
npm ERR! code EPROTO
npm ERR! errno -71
npm ERR! syscall symlink
npm ERR! EPROTO: protocol error, symlink '../node-uuid/bin/uuid' -> '/vagrant/example-app/node_modules/loopback-datasource-juggler/node_modules/.bin/uuid'
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR! <https://github.com/npm/npm/issues>
npm ERR! Linux 3.13.0-62-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "install"
npm ERR! node v4.1.0
npm ERR! npm v2.14.3
npm ERR! path npm-debug.log.2d5bb41273f18b2da30958b9aa61bfe6
npm ERR! code ETXTBSY
npm ERR! errno -26
npm ERR! syscall rename
npm ERR! ETXTBSY: text file is busy, rename 'npm-debug.log.2d5bb41273f18b2da30958b9aa61bfe6' -> 'npm-debug.log'
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! /vagrant/example-app/npm-debug.log
This is the generated package.json which has been generated by loopback framework:
{
"name": "example-app",
"version": "1.0.0",
"main": "server/server.js",
"scripts": {
"pretest": "jshint ."
},
"dependencies": {
"compression": "^1.0.3",
"cors": "^2.5.2",
"loopback": "^2.22.0",
"loopback-boot": "^2.6.5",
"loopback-datasource-juggler": "^2.39.0",
"serve-favicon": "^2.0.1"
},
"optionalDependencies": {
"loopback-explorer": "^1.1.0"
},
"devDependencies": {
"jshint": "^2.5.6"
},
"repository": {
"type": "",
"url": ""
},
"description": "example-app"
}
I have tried to run with sudo npm install but I have gotten exactly the same result.
Versions:
Node v4.1.0
Npm v2.14.3
Vagrant 1.7.4
Ubuntu Server 14.04.3 (with the newest updates)
Here is the npm-log file, it's very long.
If you know my mistake, do not hesitate, just answer :)
This is a problem with Vagrant/VirtualBox. Unfortunately, the synced/shared filesystem doesn't support symlinks.
If you don't require this functionality, the easiest thing to do is to just disable it in your Vagrantfile:
# ...
config.vm.synced_folder ".", "/vagrant", disabled: true
# ...
If you do require it, you may be able to find a work around now that you know it is a problem with symlink support, which npm uses for creating bins :-)
See https://docs.vagrantup.com/v2/synced-folders/basic_usage.html for more details.
The error happens, because your mounted shared directory (/vagrant) is on file system which doesn't support symbolic links.
To void this, you need to tell npm that your file system doesn't support symbolic links, e.g.
npm config set bin-links false
Source: npm doesn't work in vagrant at GH-7308
or by specifying --no-bin-links argument for npm install which will prevent npm from creating symlinks for any binaries the package might contain.
Alternative way is to append this to your package.json file, e.g.
"config": {
"bin-links": false
},
As said above, the synced/shared filesystem doesn't support symlinks.
SO, you can install node.js on your Windows host and execute npm install in the host code directory

Resources