How to run "npm publish" from outside of package directory - node.js

I want to run npm publish in automated script .
I try --prefix option , it does not work :
npm publish --prefix /path/to/package;

Related

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

Node & Yarn Command Means

I am trying to found
npm run install:global
npm install -g win-node-env
yarn && npm run dev:build && npm run dev:serve
What does this three command means ?
I tried to search google but not got relative info.
Without any extra info...
1:
npm run runs the next argument defined in the "scripts" property of your package.json file. So, npm run install:global will execute whatever the corresponding script entry by that name. If your package.json file has this entry (and it should):
package.json:
"scripts": {
"install:global": "npm install -g whatever-the-script-is"
}
2:
npm install -g win-node-env will globally install the win-node-env package, so that it's accessible from a terminal session by typing whatever win-node-env exposes.
3:
yarn && npm run dev:build && npm run dev:serve
Yarn is an alternative for npm. This command would run yarn, then the script in package.json that correspond to dev:build and immediately after run dev:serve.
npm run install:global
Run specified npm script
npm install -g win-node-env
Install package globally
yarn && npm run dev:build && npm run dev:serve
same as
npm install && npm run dev:build && npm run dev:serve
Install local packages and run script
This is how package.json might look like
{
"name": "demo"
"scripts": {
"install:global": "npm install -g my-unrealistic-package"
"dev:build": "echo \"build something\"",
"dev:serve": "echo \"serve something\""
}
}

npm install not working with --prefix

It seems that npm install --prefix ./server (with no args) is not working with --prefix flag. I just want to install all packages from package.json.
All I get after that command is:
npm WARN enoent ENOENT: no such file or directory, open
'/home/.../ProjectName/server/package.json'
All is fine when I put npm install package_name -S --prefix ./server for example. Then NPM will create node_modules in server and will add package_name package.
My files structure is:
ProjectName
|
+-- client
| +-- node_modules
| +-- package.json
+-- server
| +-- node_modules
+-- package.json
"Main" package.json contains all scripts (for Heroku and for me) and dependiencies for server.
client is Angular2 app that's why it has own node_modules and package.json.
I use NPM 4.2.0. With version 5.0.3 (newest?) it seems that --prefix flag is not working at all.
EDIT #1
I've just discovered that I can solve my problem with npm install (which will install node_modules in my project folder) and then copy node_modules to server/node_modules. Without that copy jasmine throws errors during tsc build.
Now I have to have node_modules in main catalog and copy of them in server. That's so odd..
EDIT #2
According to #Damian Lattenero answer:
npm --prefix ./server install ./ProjectName/package.json
or
npm --prefix ProjectName/server install ./ProjectName/package.json
IS NOT WORKING and generates:
npm ERR! code ENOLOCAL npm ERR! Could not install
"RecursiveNotebook3/package.json" as it is not a directory and is not
a file with a name ending in .tgz, .tar.gz or .tar
THIS WORKS:
npm --prefix ProjectName/server install ./ProjectName
but generates:
npm WARN saveError ENOENT: no such file or directory, open
'/home/tb/Projects/RecursiveNotebook3/server/package.json' npm notice
created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open '/home/
tb/Projects/RecursiveNotebook3/server/package.json'
and
package-lock.json next to node_modules
and
empty etc catalog next to node_modules
and
There are some problems with build (tsc -p server) with mongodb package.
Try:
npm --prefix ./server install ./ProjectName/package.json
or
npm install --prefix ./server ./ProjectName/package.json
Also, to understand better what the --prefix do, you can check this two answers:
How to npm install to a specified directory?
npm - install dependencies for a package in a different folder?
Works for me
npm install --prefix ./server ./server
Running the newest version of Ubuntu (Ubuntu 16.04.2 LTS), I encountered the same problem with npm install. I also got an ENOENT error, indicating that npm cannot find the necessary files.
When I installed nodejs-legacy, as shown here under:
sudo apt-get install nodejs-legacy
npm subsequently compiled fine, and my Angular application deployed as it should.
SOLUTION
Those lines in package.json solves all my problems:
"scripts": {
"init": "npm i && mv ./node_modules ./server && sudo npm i typescript -g",
Strange but works...
This part of my server package.json and all working fine:
"scripts": {
"start": "node dist/app.js",
"server": "nodemon --exec ts-node src/app.ts",
"build": "tsc -p .",
"client": "npm start --prefix ../client",
"client:install": "npm install --prefix ../client",
"client:build": "npm run build --prefix ../client",
"dev": "concurrently \"npm run server\" \"npm run client\""
},
Try this one it will definitely work, I'm assuming your project root directory package.json also has dependencies.
npm install && npm install --prefix ./server && npm install --prefix ./client
or user this script
"scripts": {
"client-install": "npm install --prefix ./client",
"install-all": "npm install && npm run client-install && npm run server-install",
"server-install": "npm install --prefix ./server",
},

How to run start scripts from package.json?

I've two scripts in package.json
"start:dev": "nodemon ./src/index.js",
"start": "npm run build && node ./build/index.js",
npm start works well.
I need to run "start:dev": "nodemon ./src/index.js"
For most custom npm scripts you need to add run before script name
npm run start:dev
npm - The main scripts such as start, stop, restart, install, version or test do not require run command. These scripts and some other are described in npm documentation.
npm start
The others need run command before the script name as was pointed by David.
npm run start:dev
Yarn - You can also use yarn and in that case you do not have to specify run.
yarn start
yarn start:dev

How to specify the path of `package.json` to npm?

I use npm scripts to build my project. I'd like to be able to run the scripts from a different directory. That is, instead of doing the following:
cd project;
npm run build;
cd ..
...I'd like to simply do something like:
npm run build -config project/package.json;
or
npm run build -wd project;
Is this possible?
Using --prefix worked for me:
npm --prefix /path/to/project run build
Where path/to/project is the directory where your package.json with build command defined.
to change the path of package.json that npm gets
this didnt work for me
npm --prefix /path/to/project run build
but this did
npm --prefix /path/to/project run
but this does not permanently change it
for example you can say
npm --prefix /path/to/project run test

Resources