Install package.json dependency from git, not npm

I’m trying to install gitkit but it depends on a fork of dissolve, which is only on github, not on npm. https://github.com/SamyPesse/gitkit-js/issues/6

npm on HyperDev can’t install it becuase it doesn’t have a command line git installed. Can this be fixed?

This would also allow installing custom packages by adding things like:

	"node-wirc": "git://github.com/rjmunro/node-wirc#master"

to dependencies, which would be a really useful way to test and demonstrate changes you have made to the package before making a pull request to the original author.

1 Like

Thanks for the report! We’ll look into fixing it and will update this thread when it’s released.

I know this is a year old, but I thought I would put this here in case anyone ran into this ticket and thought it was still an issue.

I was able to install a custom package inside my package.json by using

"botkit-storage-mongo": "git+https://github.com/dakotasmith/botkit-storage-mongo.git#update-monk"

So I’d say it’s fixed!

4 Likes

I think using git urls is not working at this point. I can add it to the package.json and the log says things were installed but the module fails to resolve.

Using the console and navigating to node_modules I can see that the git-based dependency is not there. If I manually run npm install the dependency seems to be downloaded correctly.

Edit: And adding a new dependency seems to cause the downloaded git repo to vanish, I have to manually run npm install again.

Edit 2: Changed my start command to "start": "npm install && node server.js" as a workaround

Preety much its the issue the node or npm version.
As I had some similar issue earlier, but when I downgraded my node version it happened to get fixed.
I hope that helps ya out.

@Froosty is right, there is a bug with the latest npm versions that makes npm prune not work correctly with git-based dependencies. After the install step, we always run an npm prune to free up some space.

We are working on a possible solution for the issue, we’ll keep you posted :slight_smile: In the meantime, the workaround proposed by @Froosty should work!

Good news! We just deployed a change that should fix this issue for every node version.

Let us know if the problem is actually solved :slight_smile:

cc: @Froosty

Its an Awesome news.

Looks like it is working for me! Thank you @etamponi

1 Like

Unfortunately I’m having the same issue as described by rajsite above on Feb 4.

I have forked an npm package called “rheostat” onto my personal Github account. It’s located here: https://github.com/MattSidor/rheostat

I added it to my package.json file like this:

"dependencies": {
  ...
  "rheostat": "git+https://[email protected]/MattSidor/rheostat.git",
  ...
},

It appeared to install correctly, but when I try to import the package, I get this error: Module not found: Error: Can't resolve 'rheostat' in '/app/src'.

Here is my full Glitch project: https://glitch.com/edit/#!/rheostat-focus-outline-demo

What is the node version you are on??
And also can you do npm ls package_name in console?

Sorry, I’m really new to Glitch. How do I check the node version from the Glitch Console? It’s not listed in my package.json file, unfortunately.

This is the result I get when I type pnpm ls rheostat in Glitch Console:

[email protected] /app
└── [email protected]/MattSidor/rheostat/d5553de1a2c6e1e47d5c0de77a96e7967d90c859

You know what, I just typed node -v in the console and I think I got the result: v6.13.1

You can usually find it in your package.json:

"engines": {
    "node": "8.x"
  },

If it’s missing, you can add it and your app will restart and run with the node version specified. :smiley:

As you’ve found, node -v works, but if it’s not specified in package.json then it may automatically upgrade at some point in the future.

Hey @MattSidor!

Yep, using node -v in the console is one way to do it. But like @jude said you can easily download any version of Node in your package.json file.

I’m sure you know how to do it as it’s really simple to do.

So now that I know what node version I’m running, how is it relevant to the Module not found error I’m getting for my github package?

The Module not found error is talking about the Node packages, so make sure you’ve told your project to download them in your package.json file:

"dependencies": {
  "express": "^4.16.3"
}

If I’m wrong and it’s not talking about your packages, could you send me a screenshot or copy & paste the error over?

I think you must have missed my original post on this topic. Here is a link to it, also you can scroll up to see it: Install package.json dependency from git, not npm

Oh, my bad! I’ve never tried grabbing packages from GitHub, but I found this and I think it might help.

If not, I’m sorry! Again, I’ve never installed dependencies from GitHub repositories.

I think I’m following the procedure correctly. The problem is that the Glitch platform does not seem to be installing them correctly. That’s the topic of this whole thread.

Ah, OK. Sorry for misunderstanding!

Hi @MattSidor,

thanks for your report. However, in this particular case, the problem is not with the Glitch platform. If you try exactly the same code on your local machine, it won’t work either.

The reason is that when you use a GitHub dependency instead of a npm package, it might not always work: it depends on whether the repository has been properly configured. Typically, npm packages do not have the proper hooks to work when fetched directly from GitHub. In this case, for example, rheostat needs to be transpiled to be used as a node package. When you fetch it from npm, the maintainers of the package transpile it before uploading it to the npm registry, so it works as expected, but this is not the case when you fetch it directly from GitHub.

If you want to use the GitHub repository for your dependency, you have to manually modify its package.json to make sure the build step is run during the install phase. You also have to make sure all the necessary packages for compilation are installed (which means you’ve to move all the devDependencies to the dependencies field).

Let me know if you need further help :slight_smile:

UPDATE: I am not a webpack expert, but you might also need to remove the node_modules exclude from your webpack.config.js file.

3 Likes

D’oh!! I should have known I was probably doing something wrong with the module import. Thanks so much @etamponi for debugging this for me and giving me a clear breakdown of the problem!

3 Likes