Is there a way to install NPM command line tools on NixOS?
[root@ip-xxx-xxx-0-27:~/teros/ntrs-cli]# sudo npm i -g typescript
npm WARN checkPermissions Missing write access to /nix/store/rhikjv5vlpa6vq4qkrszinwsaz1mda7p-nodejs-8.15.1/lib/node_modules
npm ERR! path /nix/store/rhikjv5vlpa6vq4qkrszinwsaz1mda7p-nodejs-8.15.1/lib/node_modules
npm ERR! code EROFS
npm ERR! errno -30
npm ERR! syscall access
npm ERR! rofs EROFS: read-only file system, access '/nix/store/rhikjv5vlpa6vq4qkrszinwsaz1mda7p-nodejs-8.15.1/lib/node_modules'
npm ERR! rofs Often virtualized file systems, or other file systems
npm ERR! rofs that don't support symlinks, give this error.
I assume because it's read-only, because I did run:
chown -R `whoami` nix/store/rhikjv5vlpa6vq4qkrszinwsaz1mda7p-nodejs-8.15.1
as an aside if someone knows how to install Node.js version 11 or 12 on nixos that'd be great.
The meteor-node-stubs npm package provides browser-friendly implementations of Node's built-in modules, like path , buffer , util , etc. Meteor's module system avoids actually bundling any stub modules (and their dependencies) if they are not used, so there is no cost to keeping meteor-node-stubs in the dependencies.
Firstly, please undo the permissions change (chown
) you made. You should NEVER change the permissions of files in the Nix store (/nix/store
).
To install NPM packages on NixOS use the corresponding Nix package, instead of using npm -g ...
. NPM packages are under the nodePackages
"namespace".
For example, to install typescript (tsc
) edit /etc/nixos/configuration.nix
:
...
environment.systemPackages = with pkgs; [
...
nodePackages.typescript;
]
...
Then use nixos-rebuild switch
to "install" the package.
You can install Node.js the same way. Use nix search nodejs
to see the various versions you can install.
Instead Edit ~/.npmrc
so that it tells npm
to install and find "global" packages in your home folder instead of the root location:
prefix=~/.npm-packages
now any time you run npm i -g <some-package>
you will see that it will be installed inside of ~/.npm-packages
.
Now in your shell rc file (f.e. .bashrc
or .zshrc
or similar), you'll need to update your PATH
to include executables from the new location:
### Add NPM executables to your PATH so that they are available as commands:
export PATH="$HOME/.npm-packages/bin:$PATH"
Often it is more convenient to manage ephemeral dependencies outside of the system-level package manager.
If you use something like n
or nvm
to manage specific node versions, you can do a similar thing by managing them in your home folder.
npm config set prefix '~/mutable_node_modules'
This thread should be helpful:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With