• TODO: This will still break if there's a conflict with other dependencies in package.json

I recently ran into a problem where I needed a package, but the existing set of npm packages would break if I installed the one I needed. This is because they needed a different Node.js version.

So here's what I did.

  1. Switch to my desired version of node:
nvm use v16
  1. Install the required package without saving
npm install --no-package-lock --no-save tailwindcss@^3.3.0
  1. Define a script in package.json and then run it:
"scripts": {
    "twdev": "tailwindcss -i ./tailwind/styles.css -o ./app/assets/stylesheets/tailwind.css --watch"
  1. As an additional step I could switch back to the node version they were using earlier in a shell script
# Make note of current node version
nvm ls
# Store that in a variable and switch to that with
nvm use <prev-node-version>