I have done some changes inside node_modules folder inside a module and run NPM install again inside a module in node_modules. It's working fine on local.
Now, I want to deploy it on Heroku. But Heroku looks at the package.json file and installs all the NPM modules again.
So, Please let me know "How can I deploy local node_modules folder onto Heroku" and prevent Heroku to NPM install again.
Related
I am using "firebase-functions": "^3.6.0", "firebase-tools": "^8.0.0" to deploy my Angular: 10.0.14 app. All was working fine until I decided to move some components into a library created using the command ng generate library and made the package a submodule in my project under ./projects/my-lib
I build the lib using ng build my-lib
Then in my package.json installed the lib from file
"my-lib": "file:dist/my-lib"
I installed the package locally and it works fine when I test it locally but deploying using ng deploy raised the error
npm ERR! Could not install from "dist/mce-lib" as it does not contain a package.json file.
I have tried a couple of solutions I found online, but no luck yet
Try this
First, remove node_modules and package-lock.json file
rm -rf node_modules package-lock.json
Then, clean cache
npm cache clean --force
And last re-install modules
npm i
You need to create the library by using
ng generate library <your lib name>
This will setup your lib with the necessary files so that you can add it as a dependency.
Otherwise, if you want to do this manually it'll require more work.
UPDATE:
To be able to use the lib above locally without publishing you will need to do the following
From withing your app directory for which you generated the lib, go into ./projects/ as it was generated by the lib command above. Then run the following build command
ng build <your lib name> --prod
The prod tag is optional but it helps to run your code in that flag so that it is the closest to what it will look like once you publish
Then go back to your app root folder and install the application by referencing the dist folder. The build command above should have added your lib as its own folder withing dist
npm install ./dist/<your lib name>
NOTE: All of this is for dev testing purposes. Ideally, you will want to publish your lib to npmjs or github packages first and then install it properly in your app before you deploy your app to production
Another way of locally: though the use of npm link
cd ./dist/<your lib name>
npm link
Then going back to root folder of app, you should be able to run the installation as such
npm link <your lib name>
This creates a local link to your library in your app for testing purposes that doesn't modify your package.json file as installing the directory directly does. Once you are done, always make sure to run unlink
npm unlink <your lib name>
And withing your ./dist/
npm unlink
So after hours of trying to figure out how to solve this, I came across these resources that helped me to resolve the issue:
https://firebase.google.com/docs/functions/handle-dependencies#including_local_nodejs_modules_as_part_of_your_deployment_package
Note: The Firebase CLI ignores the local node_modules folder when deploying your function.
Firebase Functions local "file:" dependencies
So even if the app was working locally, the node_modules isn't deployed
Since I had installed python packages from git before, I thought why not make use of this? I am using Gitlab and this answer really helped me https://stackoverflow.com/a/50314604/3247914
I got it working by installing my package from git
I created my own npm package from a fork of react-coverflow. It appears to be working fine in my app locally using it this way: "npm install react-coverflow-mod" --save.
I can run my app using "run with debug (F5)" in VsCode and npm start on the client folder to start the React front end.
Then I do an npm run build on the client folder, and it works just fine.
When I do a heroku push it fails everytime with this error:
npm ERR! code ENOLOCAL
npm ERR! Could not install from "../../react-coverflow-mod"
as it does not contain a package.json file.
1. I know there is a package.json in the module because I can install it via "npm install react-coverflow-mod": https://www.npmjs.com/package/react-coverflow-mod
2. The installed module has a package.json file in it
3. My github repo has a package.json in it: https://github.com/leroyvaughan/react-coverflow
I'm not sure how I can fix this. Do I need a package.json to go into the /Dist folder? What is wrong here with Heroku.
It seams like heroku try to install a package from a relative path instead of the published name. That would perfectly explain why you can run locally but not on a production environment.
Open your project and search for the exact string displayed in your log: "../../react-coverflow-mod" and you should be able to find quickly where it is.
If you run on a unix system (don't know about windows) you can do a search using grep:
grep -rnw '/path/to/somewhere/' -e '../../react-coverflow-mod'
Make sure it includes your root folder which contain package.json, and might we wise to ignore node_modules which is always massive.
I have a node application in which I am using package.json file which on npm install make a node_modules folder inside the application folder which have all dependencies in it. I want to move node_modules folder out from application folder without causing the code break. Basically I want to manually configure the location of local node modules. How can I do that?
I an running a react project locally. I want to now run from a remote server, is the node_modules directory necessary to have on the server?
If there are dependencies with particular node modules, of course, yes. Try to remove the folder and run your app. If there are errors, try to 'npm install' and run again. If it works, you need to include node modules folder.
I have a node app that has a local npm module npm link ./local and I'm trying to deploy the app to heroku. Heroku runs npm install when I deploy, but npm link's aren't saved in package.json so my local module is missing.
I'm new to heroku and Procfiles, I'd like to run a script or just run npm link ./local before on the heroku box.
Alternatively I could put the module on github as a private repository and link it from there. But as far as I know Heroku isn't able to download private repo. Can I give Heroku access to my github repository via keys so that it could download it?
I'd love for somekind of solution! Anything!
I think you need yo put modules in node_modules folder and push that to heroku
Procfiles are easy to maintain and heroku will read that
I have sample Procfile like
web: bin/hubot -a campfire
Even heroku also says that best is to include node_modules into repo so you can just include your local packages into that.
See more here Heroku Node Deploy