How do I require a specific version of an npm package?

This topic was automatically generated from Slack. You can find the original thread here.

Rodrigo Zuini : Hey guys. I just found out that an npm package (mssql/tedious) that I use was released a new buggy version but still has no deadline for resolution. Is there any way to use a specific version in my requires?

Dylan Sather (Pipedream) : thanks for reaching out. Are you using this npm package in a workflow or an event source?

Rodrigo Zuini : Hi . I am using in workflow.

Dylan Sather (Pipedream) : thanks. Which npm package is it?

Rodrigo Zuini : mssql/tedious

Rodrigo Zuini : the current version of tedious can’t identify tables in bulk operations.

Dylan Sather (Pipedream) : just to confirm, is it this package? GitHub - tediousjs/node-mssql: Microsoft SQL Server client for Node.js

Rodrigo Zuini : Yes, the problem is in dependence on this package (tedious). Version 11.0.10 works on my local machine, but for that I need to remove the tedious folder and install again with npm install tedious@11.0.10. I don’t know how to solve it that way on the Pipedream platform so I plan to roll back the mssql version to the point where the tedious works.

Rodrigo Zuini : , this is the issue opened in github project with more details: Bulk operations suddenly stopped working. · Issue #1276 · tediousjs/node-mssql · GitHub

Dylan Sather (Pipedream) : Thanks. We don’t yet have a way to require a specific version of a package in a workflow (tracking here, if you’d like to follow), but here’s what I do when I need to do this:

  1. Clone the repo for the package on your local machine
  2. Checkout the commit pointing to the version I’d like to use. Since they use Git tags in this repo, you should be able to git checkout <version> .
  3. Change the name in the package.json to reference a scoped package name under my npm namespace. For example, I’d change the name to @dylburger/mssql , where dylburger is my npm username.
  4. Publish the package to npm
  5. In my workflow, I require("@dylburger/mssql") to reference my scoped package, which now points to the version I originally checked out in step 2.
    Let me know if that makes sense.

Rodrigo Zuini : Hmm that makes sense. I will do a test and return soon. Thank you so far

Rodrigo Zuini : , your trick worked perfectly. Thank you!

Dylan Sather (Pipedream) : Good to hear. Thanks!