Search code examples
javascriptnode.jsnpmversion

How to import certain node module version?


How would you import a specific version of a node module? I know in npm you can do npm i someModule@1.0.0 But whats not what I'm looking for. I so far I have like this:

// File 1
const fetch = require('node-fetch@2.6.6');

// File 2
const fetch = require('node-fetch@3.1.0');

Any help would be appreciated. Thank you.


Solution

  • I found my answer here. Thank you @szulbix for sending me this.

    I ran npm i node-fetch-commonjs@npm:node-fetch@2.6.6 and then imported using

    const fetch = require('node-fetch-commonjs');
    

    I hoped this helped other people who come across this thread!