简体   繁体   中英

How to include 3rd party npm module without npm install?

I need to use a 3rd party npm module, it's very old, I cannot directly use it with npm i and reqiure , I have to modify some source code of this npm module for my special use case.

So I'm thinking to clone the source code of the npm module to my source code base, and use it directly.

As the npm module is not a pure JS module, it contains some C code. I have no idea how to do this.

Could you give me some guidance?

For example, let's say the 3rd party npm module is request , so generally I just npm i --save request and then in my code I can use it like this

const request = require('request');

Since what I want is to modify some request code, so I will download request source code from https://github.com/request/request , and maybe put the lib folder into my project's root.

Then how can use request from this lib folder?

  1. let's say this request includes some c code, how can I use it from lib again?

You can install from a local folder where you have done the modifications

npm install /path-to-local-folder

To get this into package.json use

   "dependencies":
  {
    "mymodule": "file:./path-to-folder",
    "request": "^2.5"
  }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM