(Nodejs) Can't npm install with -g with Nix, but if I use modules, it won't let me install Python

Question:

See the title. I’m trying to install the gritty command using npm. It requires npm install gritty -g but it won’t install as I need the python command. Normally I’d just add Python with Nix, but seeing how that is gone, I didn’t know what to do. Until I did. I forked one of my older repls with both nodejs and python as well as other languages installed (https://replit.com/@doxr/All-Languages) and tried to install gritty. I got a different error:

npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /nix/store/vh6xzs18qyyd2zfa400vqlcpprlgwmhh-nodejs-19.1.0/lib/node_modules/gritty
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, mkdir '/nix/store/vh6xzs18qyyd2zfa400vqlcpprlgwmhh-nodejs-19.1.0/lib/node_modules/gritty'
npm ERR!  [Error: EACCES: permission denied, mkdir '/nix/store/vh6xzs18qyyd2zfa400vqlcpprlgwmhh-nodejs-19.1.0/lib/node_modules/gritty'] {
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'mkdir',
npm ERR!   path: '/nix/store/vh6xzs18qyyd2zfa400vqlcpprlgwmhh-nodejs-19.1.0/lib/node_modules/gritty'
npm ERR! }
npm ERR! 
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user

I think this is because npm is not allowed to make files in /nix/store/vh6xzs18qyyd2zfa400vqlcpprlgwmhh-nodejs-19.1.0/lib/node_modules/ (required action for -g). Modules don’t have this problem as it doesn’t use Nix but with that I can’t install Python. Gritty installed successfully without -g but it didn’t work properly (this is a problem with Replit; it works fine with GitHub codespaces which has both Nodejs and Python installed already and it allows you to globally install)

So now what? I need a solution to install Python and Nodejs with Modules as I think the Nix thing is something I can’t work with.

Edit: gritty is a command you have to install with npm. Without -g it won’t run. Should have said that.

1 Like

Why won’t it run? Can’t you just run it locally and then use npx gritty?

1 Like

Bash won’t find the command

If this works I’m going to feel stupid

so yes I am dumb but yeah it works idrk what npx is, but I did try it on my phone and it works. Thanks!

1 Like

Basically when you install a package globally, npm puts the package scripts into a folder that’s typically on your PATH, so you can just run it with the script name.

When you install it locally, package scripts go somewhere in the local node_modules, which isn’t on your path. npx (node package executer?) will search node modules for the script and run it

1 Like

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