Heroku Run Npm "Command Not Found" - node.js

Based on this question, when I try to run the suggested answer (heroku run npm run "script name") I get "bash: npm: command not found". I'm trying to trigger the script on a deployed meteor NodeJS app to Heroku (node version 4.8.2 and npm version 4.6.1). Any solutions to why?
package.json
{
"name": "admini_meteor",
"private": true,
"scripts": {
"deploy": "MONGO_URL=mongodb://52.1.130.211/cloud meteor"
},
"dependencies": {
"babel-runtime": "^6.23.0",
"bcrypt": "^1.0.2"
}
}
Procfile
web: npm run deploy

You need to add nodejs in your buildpack
And then deploy your app again! That's all!

I am no expert but I will try to give you a hint of your problem because I had the same one. Everything is in the docs you just need to read it.
So far the web process in the one taking care of running the actual app/server like here.
But also how is your project structure? Heroku detects you are developing a node project (because of package.json file in root directory) so it should install npm for you.
In my case I was developing a Laravel app, therefore, it created a PHP application without node and npm. There is a way to tell heroku you need both environments like state here

Related

How can I deploy a Vite Node.js app on Heroku? Everything I do seems to build but fails to run

I am deploying using Github (automatic fetching and building from the repository). The project version there is the dev version, but since Heroku builds it first, it shouldnt be a problem.
First Heroku fetches and builds the project, which always succeeds:
See here
But, right after that, when Heroku tries to run and deploy the build, it says "vite" is not found:
See here
If i run it locally it works. If i build and preview it locally it also works.
Does anyone know what I should do to make this work?
I tried checking my package.json for "dependencies" vs "devDependencies" differences and added "vite" to the "dependencies" section:
See here
The Procfile they advise to use I've tried running "npm run start", "npm start", "npm i && npm start" and "npm i && npm run start", but all of them give the same exact error. Also tried it with "npx" but it fails to install vite.
After i contacted their support, they just said it falls outside of their "support policy".
I just want this to be able to run, since it works when i run it locally and when i build and preview it.
EDIT: After moving both vite and vite plugins to the dependencies instead of the devDependencies, i got this message See here

Cannot deploy firebase cloud functions, because functions/lib/index.js does not exist

I think there is a bug in firebase cloud functions setup.
I did:
npm install -g firebase-tools
firebase init functions
I have configured it for typescript, everything installed, yet I cannot deploy the functions because I am getting this error message:
Error: There was an error reading functions/package.json:
functions/lib/index.js does not exist, can't deploy Cloud Functions
I know that it does not exist - there is no lib folder at all, but what can I do to run the functions?
Why I can't run functions, if I done everything that needed to be done?
I understand you might be following the instructions from the Getting started guide or the Use Typescript for Cloud Functions one, during this section the wizard helps you choose Typescript as your language to write Functions. Please be sure the language and its dependencies are correctly installed. And in this last guide for the Using an existing Typescript project, it asks you to edit the package.json to add a bash script to build your typescript project:
{
"name": "functions",
"scripts": {
"build": "npm run lint && tsc"
}
...
and the firebase.json to add a predeploy hook to run the build script:
{
"functions": {
"predeploy": "npm --prefix functions run build",
}
}
but in this case, you need to check if this configuration was made during the installation.
You can check this answer where the user used sudo npm install typescript to install them, and as Doug mentions try to install it only in your project, not globally; and it must be defined in your package.json as well.
Another example that fixed a similar issue where:
The user removed everything related to Firebase Functions
Entered in the project directory using cd functions (in this case replace the ‘functions’ name for your project)
Ran npm install
Running again firebase init
Let me know if you were able to solve this problem to further assist you, trying to add more information as steps and documentation followed and the logs.
Open a terminal and cd to functions
Then run npx tsc --watch
And try serving and deploying the project

npm install fail for multiple versions of node

I'm not very used to working with node and I'm having a nightmare installing the packages for a project.
I'm using vagrant/VirtualBox Homestead on Windows 10 for a Laravel (5.2) project. When doing npm install I've had a whole bunch errors - I can't remember them all specifically, but I'm wondering if there is some big picture issue I'm missing.
My first attempt was with a recent node node version - 12.something I think.
Then I was told that "some of those older projects used v8, I think", so I used nvm to do that and got a whole bunch of different issues. Some involved sym links, so I deleted node_modules and tried with --no-bin-links. That didn't work, and one of the errors, when I looked on SO, was down to node version, so I tried v9.0.0, which gave different problems.
How hard can it be?
I don't know enough about this frontend stuff to know if it's normal to have so much trouble, or if I have not been given sufficient information - e.g. "you absolutely need to use node version 8.1.3, with these specific other details..." or something like that.
Does anyone have any suggestions on how to get this working? The node-sass package seems to be a significant culprit in the overall failage of the installation...
Below is my package.json
{
"private": true,
"scripts": {
"prod": "gulp --production",
"dev": "gulp watch"
},
"devDependencies": {
"gulp": "^3.9.1",
"laravel-elixir": "^5.0.0",
"bootstrap-sass": "^3.0.0"
},
"dependencies": {
"node-sass": "^4.1.0"
}
}
I was heading same problem last time. Here is what I did:
Using terminal in homestead directory run command vagrant plugin install vagrant-winnfsd it will install plugin that allows you to use NFS protocol on Windows.
Edit you Homestead.yaml file like that:
folders:
    - map: ~/Projects
    to: /home/vagrant/code
    type: "nfs"
Run command vagrant reload --provision. After that when you use secure shell - vagrant ssh you should be able to run npm install from inside you project directory.

Zipping up Node App and having dependencies work out of box

I created a Node app that relies on a dependency (Jest) that is just for running tests.
I want to zip this app up and run it and its tests on another machine that has node installed.
My package.json includes
"scripts": {
"test": "jest"
},
and jest is included in the app's npm_modules folder.
The tests work perfectly on the machine that the app was developed on. However, upon extracting the zip and running on another computer, I get an error that jest is not found.
I then reinstalled jest without '--save-dev' and installed it for production use, thinking this would resolve the error, but it did not.
I thought the point of having npm_modules and using 'npm install' was so that the app's dependencies can all be localized and portable i.e. not having host machine have to install modules separately.
Is there any way to resolve this? Thanks!
According to "scripts": { "test": "jest" }, you have jest installed globally on source machine. Change it to "scripts": { "test": "node_modules/.bin/jest" },
Try using pkg
Github Page
npm
If you just need to run it on the second machine, pkg should let you package it as a standalone executable.
I'm guessing the problem is either that Jest installs differently based on the OS. It may also be a problem with import-local, one of the packages that Jest depends on.

Set up Socket.IO to run on Node Windows

I am new to programming and I am doing the WebRTC codelab here: https://codelabs.developers.google.com/codelabs/webrtc-web/#6
I am at the part titled "Set up Socket.IO to run on Node" where it says "To install dependencies, run the following from the command line terminal in your work directory:
npm install", however, when I type npm install the command prompt in Windows, it does not recognize the command. I feel like this should be pretty easy, so am I missing something?
Set up Socket.IO to run on Node
For this and the following steps, you'll run Socket.IO on Node.
At the top level of your work directory create a file named package.json with the following contents:
{
"name": "webrtc-codelab",
"version": "0.0.1",
"description": "WebRTC codelab",
"dependencies": {
"node-static": "0.7.7",
"socket.io": "1.2.0"
}
}
This is an app manifest that tells Node Package Manager (npm) what project dependencies to install.
To install dependencies, run the following from the command line terminal in your work directory:
npm install
You should see an installation log that ends something like this:
enter image description here

Resources