shreshthmohan / next-blog

next-blog-mu-three.vercel.app
2 stars 0 forks source link

Installing an npm package without saving to package.json or lock files #93

Open shreshthmohan opened 1 year ago

shreshthmohan commented 1 year ago


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
  2. Install the required package without saving
    npm install --no-package-lock --no-save tailwindcss@^3.3.0
  3. Define a script in package.json and then run it:
    "scripts": {
    "twdev": "tailwindcss -i ./tailwind/styles.css -o ./app/assets/stylesheets/tailwind.css --watch"
    }
  4. 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>