Search code examples
node.jsherokunpmbackendnode-modules

Publish app with js file changed in nodemodules


I have created App with some node packages, and cause I couldn't access some classes from my script, I changed the script in node_modules. It works fine when I host it (node|nodemon app.js). The problem starts when I try to deploy it. Cause of the .gitignore I'm ignoring the node_modules, and when app is deployed (Heroku in this case) Uses npm install to install dependecies. But when it installs the dependency which I have changed, Logically it doesn't install same dependency as I have on my local machine. I tried to remove node_modules from .gitignore, but it didn't work either.

So: How can I publish node app when I have changed (even sligthly) file in node_modules?

Thanks for help!


Solution

  • You should never do any changes in node_modules.

    If you want to make changes in a existing package:

    1. Fork the package you want to change.
    2. Make the changes on your forked version and commit them.
    3. Finally replace the package version number to an direct git repository url in your package.json i.e.:

    from:

    "packagename": "^1.0.0",
    

    to:

    "packagename": "git+https://github.com/YourGitHubUserName/packagename.git",