Pnpm does not add dependencies

I cannot seem to get dependencies to load into my package.json file automatically. By automatically, I mean that when I install the package from pnpm, using
pnpm install <package> --save
the package.json file does not get updated with the dependency. What is driving me crazy is that 2 weeks ago it was working (sometimes, depending on the package installed).
I know there is an “add package” button, but it’s not the proper way of adding a package (because that button does not exist anywhere else).
I have tried enable-pnpm, removing node from dependencies, no changes. I would prefer to not have to copy and remake my package.json file for every project, as that is the only “fix” I have seen, which is not a fix, just more work. Is there an answer or is this just an existing bug waiting to be fixed?

1 Like

Can you try running pnpm install <package> --save in a new project and let me know how that works?

The --save should be optional these days. I will guess that it is has added the package but you are not seeing it in package.json because you are in the terminal when you install the package. Did you run refresh afterward?

Maybe you have but that sounds unusual. You might try npm instead if that is the case and report your findings.

I just tried this with the same result. Nothing is added to dependencies.
Also tried pnpm update, which showed all the dependencies but nothing updated in package.json and also not appearing on the add package button list.

1 Like

I have done all of the above, except I am not sure what you mean by “run refresh” as there is no command for npm or pnpm matching that (have tried pnpm/npm update). If it refers to whether I have refreshed the browser, yes and no change. Also tried npm, no change. I’m just tired of having to manually add everything I just manually added.

sorry about that “refresh” is apparently a program that Glitch uses to sync the UI view with changes made in the terminal window. If you add a file there or in your case install something the view does not change until you refresh the UI.

It is possible that something is amiss in your project but I tried it and it worked for me.

1 Like

Hi @James_Ragain, if you’re doing file edits via the terminal, you’ll need to run refresh in the terminal afterwards so the changes sync with the Glitch editor. Installing packages should update package.json so if you run refresh after and it doesn’t work, email support@glitch.com with the name of the project and we’ll take a look!

The refresh command worked…

The refresh command did work, but why is it necessary? Since it is, why isn’t a package install flagged with a console message that refresh must be run to add the dependency to package.json? This is the first that I have heard of this command, and never would have thought to look for it since I’ve never needed an additional command to update a package.json before, especially after giving the argument --save, which to my understanding is to direct the package manager to save the dependency to package.json.

We don’t automatically sync it because of significant performance issues we encountered when we had tried syncing awhile ago. If you open the terminal, it says For now, the console and the editor don't automatically sync. You can manually run the refresh command and it will force a refresh, updating the editor with any console-created files. I’ll let the team know, though, that we should see if there’s a way to make it more obvious since it is a Glitch-specific command!

Jenn. I don’t know if it performs a sync “somewhere” automatically but as part of the startup would seemingly be a low-impact place to handle it. At least if someone installed a package or added a file, got confused and left it would be synced upon their return to the project.

Maybe it does that already I have no idea.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.