npm ERR! missing script: deploy - node.js

I am deploying my application to github pages but when I run command npm run deploy but i get error
npm ERR! missing script: deploy
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\whoami\AppData\Roaming\npm-cache\_logs\2020-02-05T16_46_06_946Z-debug.log
I have defined deploy in my package.json file
...
"scripts": {
"test": "jest --watchAll --verbose --coverage --runInBand",
"start": "node index.js",
"predeploy":"npm run build",
"deploy":"gh-pages -d build"
}
...

make sure you have save package.json file. In my case i have not saved it so that is why error is coming

Please check the terminal path. In my case, I forgot to change the directory inside my project.
Simply type the following:
cd *name-of-your-project*

Please close the current working terminal and open new terminal and try the command again.

Related

Npm start and npm run build, why to use `run` when build? [duplicate]

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.

How do I run my nodejs application with nodemon?

Problem
Sorry in advance for asking a newbie question but I do hope anyone can help because I've been stuck for a few hours. I am currently working on a student portal assignment to develop a Backend API that reads from csv and stores into the database.
I'm having a very basic trouble of running or starting the Node Application.
Project Directory
Assignment
- .vscode
- external
- config
- controllers
- services
- app.js
- external-system.Dockerfile
- package.json
- packagelock.json
- router.js
- server.js (localhost:5000)
- javascript
- src
- config
- const
- controllers
- errors
- utils
- app.js
- router.js
- server.js (localhost:3000)
- database
- node_modules
- .babelrc
- .env
- .env.sample
- .eslintrc
- docker-compose.yml
- package.json
- packagelog.json
- file.csv
Anyway in short, the javascript folder is where I will have to retrieve the csv file, create the API and storage to the database for the full time students. The external folder is where I have to retrieve the information it and because they are not full time students. (FYI: The directory is given and fixed)
What I've tried
I tried an npm start to the javascript folder but I have the following error when trying to run localhost:3000.
> student-portal-system#1.0.0 prestart C:\Users\User\Desktop\Assignment\javascript
> npm run start:services && npm run build
> student-portal-system#1.0.0 start:services C:\Users\User\Desktop\Assignment\javascript
> docker-compose up -d
'docker-compose' is not recognized as an internal or external command, operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! student-portal-system#1.0.0 start:services: `docker-compose up -d`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the student-portal-system#1.0.0 start:services 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-09-13T15_27_31_396Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! student-portal-system#1.0.0 prestart: `npm run start:services && npm run build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the student-portal-system#1.0.0 prestart script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
In javascript directory(package.json)
{
...
"scripts": {
"test": "jest",
"build": "babel src --out-dir build",
"prestart": "npm run start:services && npm run build",
"start": "node ./build/server.js",
"prestart:dev": "npm run start:services ",
"start:dev": "nodemon --exec babel-node src/server.js",
"start:services": "docker-compose up -d",
"lint": "eslint \"src/**/*.js\""
and so on...
In external directory(package.json)
{
...
"scripts": {
"test": "jest",
"build": "babel src --out-dir build",
"prestart": "npm run build",
"start": "node ./build/server.js",
"start:dev": "nodemon --exec babel-node src/server.js",
"lint": "eslint \"src/**/*.js\""
... and so on ...
Would be great anyone could give some tips on how to resolve the errors or correct me whether I am running the application correctly. Appreciate it!
Seems like you do not have docker installed on your windows.
Check this https://docs.docker.com/docker-for-windows
But I am not sure that if you install just docker, the docker-compose will be also installed, in that case
you would need also install https://docs.docker.com/compose/install/ there is a Tab for installing it on windows.
Also I am not sure if you have a typo in docker-compose.yml file, I see that there is
docker.compose.yml filename which is wrong.

'sed' is not recognized as an internal or external command in Windows

I'm using gatsby mate portfolio but recent local development shows error when I run npm start:
'sed' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! gatsby-starter-mate#2.5.1 fix-medium-plugin: `sed -i' ' 's//latest//g' ./node_modules/gatsby-source-medium/gatsby-node.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the gatsby-starter-mate#2.5.1 fix-medium-plugin script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
It seems that it's not properly escaping s //
Here's package.json copy of the line it specified:
"name": "gatsby-starter-mate",
"version": "2.5.1",
"description": "Gatsby v2 starter to create a top notch portfolio!",
"main": "index.js",
"scripts": {
"fix-medium-plugin": "sed -i' ' 's/\/latest//g' ./node_modules/gatsby-source-medium/gatsby-node.js",
"prepare": "npm run fix-medium-plugin && gatsby clean",
"build": "npm run prepare && gatsby build",
"develop": "npm run prepare && gatsby develop",
"start": "npm run develop",
"serve": "npm run build && gatsby serve -p 9000",
"lint": "eslint ./src",
"setup": "node ./bin/setup.js",
"e2e:open": "cypress open",
"e2e:ci": "DETERMINISTIC=true start-server-and-test serve http://localhost:9000 'percy exec -- cypress run'"
},
sed is a Unix command. You're likely within powershell in VSCode, you can still use this Gatsby starter you'll just need to run npm start within a unix terminal.
You can install cygwin path into your gatsby directory and enter npm start there and it will run successfully.
I have created a new gatsby project using this mate starter reached the same problem you are having and then confirmed with the creator of mate that there are no alternative solutions at this time other than running it via a unix terminal. Here is a link to the commit that occured on the 21st October 2019 that caused this problem for you and there you will find EmaSuriano's solution to your problem :)

How do you correctly use parallelshell with npm scripts?

I am trying to use parallelshell with my node project on Windows to run two processes at the same time.
Here is the scripts section of my package.json file:
"scripts": {
"start": "npm run watch:all",
"test": "echo \"Error: no test specified\" && exit 1",
"lite": "lite-server",
"scss": "node-sass -o css/ css/",
"watch:scss": "onchange \"css/*.scss\" -- npm run scss",
"watch:all": "parallelshell \"npm run watch:scss\" \"npm run lite\""
}
When I run the command npm start I get this error log:
TypeError [ERR_INVALID_ARG_TYPE]: The "options.cwd" property must be of type string. Received type function
at normalizeSpawnArguments (child_process.js:420:11)
at spawn (child_process.js:522:38)
at C:\Users\Daniel\Documents\development\online_classes\coursera_uhk_web_dev\Bootstrap4\conFusion\node_modules\parallelshell\index.js:104:17
at Array.forEach (<anonymous>)
at Object.<anonymous> (C:\Users\Daniel\Documents\development\online_classes\coursera_uhk_web_dev\Bootstrap4\conFusion\node_modules\parallelshell\index.js:100:6)
at Module._compile (internal/modules/cjs/loader.js:702:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10)
at Module.load (internal/modules/cjs/loader.js:612:32)
at tryModuleLoad (internal/modules/cjs/loader.js:551:12)
at Function.Module._load (internal/modules/cjs/loader.js:543:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! confusion#1.0.0 watch:all: `parallelshell "npm run watch:scss" "npm run lite"`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the confusion#1.0.0 watch:all script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Is there something wrong with my syntax? I can run the commands npm run watch:scss and npm run lite individually and they work fine, but I am not able to run the parallelshell command.
Thank you!
Try downgrading the parallelshell version from 3.0.2 to 3.0.1
According to the statement, it is just a temporary fix.
https://github.com/darkguy2008/parallelshell/issues/57
Below is the command line syntax to for downgrading parallelshell:
sudo npm uninstall --save-dev parallelshell#3.0.2
sudo npm install --save-dev parallelshell#3.0.1
It worked for me.
Hope this helps and let us know.
parallelshell is giving active errors at every use. Instead of parallelshell the alternative here is to use npm-run-all dev-dependency.
install npm-run-all
npm install --save-dev npm-run-all
then make active changes in scripts of package.json shown below.
"scripts": {
"start": "npm run dev",
"test": "echo \"Error: no test specified\" && exit 1",
"lite": "lite-server",
"scss": "node-sass -o css/ css/",
"watch:scss": "onchange \"css/*.scss\" -- npm run scss",
"dev": "npm-run-all -p watch:scss lite"
}
All correct to be run on Windows OS. Just simply try to install parallelshell#3.0.1:
npm install --save-dev parallelshell#3.0.1
and then call npm start again.
change a line in your node_modules/parallelshell/index.js:105 file
from: cwd: process.versions.node < '8.0.0' ? process.cwd : process.cwd(),
to: cwd: parseInt(process.versions.node) < 8 ? process.cwd : process.cwd(),
reference: Problem running parallelshell Nodejs script
This is due to incompatibility of the npm with the version of parallelshell.
Try downgrading it to 3.0.1 by using:
npm i --save-dev parallelshell#3.0.1
Worked for me 100%.
It looks correct to me, instead of escaping your double quotes you could use single quotes inside the double quotes.
Not sure if it will make a difference.
"watch:all": "parallelshell 'npm run watch:scss' 'npm run lite'"
Is different for MAC and Windows machines.
User single quotes on MAC and "\ "\ on windows.
Also downgrade to parallelshell to 3.0.1 to work with \"
I changed to use concurrently package, and it works well for me on win64, the method mentioned is in the post.
I just simply use "watch:all": "concurrently \"npm run watch:scss\" \"npm run lite\"" to replace "watch:all": "parallelshell \"npm run watch:scss\" \"npm run lite\""
This is a common issue can not be fixed using npm audit fix. All you can do is to copy the actual index.js file of parallelshell into your node_modules directory.
So to do it below are the instructions:
1. Go to https://raw.githubusercontent.com/darkguy2008/parallelshell/master/index.js
2. Copy the content here.
3. Now go to the directory of your project, it may be something like /project/node_modules/parallelshell/index.js
4. Inside the index.js replace the contents with the one you copied from the link in Step 1.
5. Save the file and exit.
Hope this fix will work for you.
If someone is still running into errors after altering the index.js or after demoting to 3.0.1 version, a better alternative would be using npm-run-all

Firebase Function Deployment issue: package.json not found in %RESOURCE_DIR%

I having problem of deploying Firebase Cloud Functions.
Steps to reproduce
firebase init
select function only
select Firebase Project
select Javascript
use ESLint
install dependencies with npm now
Run firebase deploy
Expected Result
Expecting firebase-tools to deploy the cloud functions.
Actual Result
Receive the following error message:
λ firebase deploy
=== Deploying to '<projects>'...
i deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run lint
npm ERR! path ...path\firebaseFunction\%RESOURCE_DIR%\package.json
npm ERR! code ENOENT
npm ERR! errno -4058
npm ERR! syscall open
npm ERR! enoent ENOENT: no such file or directory, open '...path\firebaseFunction\%RESOURCE_DIR%\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! ...path\AppData\Roaming\npm-cache\_logs\2018-06-17T10_02_45_577Z-debug.log
Error: functions predeploy error: Command terminated with non-zero exit code4294963238
I have tried googled it and follow the solutions on below link but it doesn't work to me:
https://github.com/firebase/firebase-tools/issues/610
Please help!
Thank you.
Try replacing the string "$RESOURCE_DIR" with "%RESOURCE_DIR%" in your "firebase.json" file.
Now run the deploy command again. It worked for me.
Explanation: This fix is for Windows because %RESOURCE_DIR% will be recognized as an environment variable only by Windows command-line interpreters. As an ultimate consequence, the project isn't cross-platform anymore, as mentioned in the answer of this similar question.
1. In firebase.json file
try and replace $RESOURCE_DIRwith %RESOURCE_DIR%
and
"npm --prefix $RESOURCE_DIR run lint" to "npm --prefix %RESOURCE_DIR% run lint"
(the above one just worked around )
2. npm install -g git://github.com/firebase/firebase-tools#master
please try this installation again in ur project folder it should solve the issue
I had the same problem just remove the predeploy from firebase.json file and it will work fine
It looks like you're either using an old version of the Firebase CLI, or a project that was initialized with an old version. The cleanest thing to do would be to upgrade your CLI:
npm install -g firebase-tools
And create a whole new project from scratch with firebase init. Then, reconstruct your new project with the code from the old project.
Solution
"functions": {
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint",
"npm --prefix \"$RESOURCE_DIR\" run build"
]
}
to
"functions": {
"predeploy": [
"npm --prefix \"%RESOURCE_DIR%\" run lint",
"npm --prefix \"%RESOURCE_DIR%\" run build"
]
}
Step1: open firebase.json you will show this JSON file
"functions": {
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint",
"npm --prefix \"$RESOURCE_DIR\" run build"
]
}
Step2: Delete "npm --prefix \"$RESOURCE_DIR\" run lint", and "npm --prefix \"$RESOURCE_DIR\" run build"
"functions": {
"predeploy": []
}
Now deploy, it works fine

Resources