Skip to content
Advertisement

Can’t npm install local dependency

I’ve been using npm install react-financial-charts successfully. However, I want to include this package locally instead (for reasons), so I checked out the master branch of react-financial-charts from Github. I now have two folders:

JavaScript

Inside of my project, my package.json contains:

JavaScript

npm run dev will now encounter the compile error corresponding to a basic import statement import { BarSeries } from "react-financial-charts" in one of my files:

JavaScript

So basically, the simple import statement which used to work (when I was doing npm install react-financial-charts), is now no longer working when I install the dependency from a local folder instead.

EDIT: I also tried these things that an answer below suggested, but I’m getting the exact same error message:

JavaScript
JavaScript
JavaScript

EDIT 2: This ended up working, thanks to the suggested answer below. The trick was I needed to npm update and npm install inside the dependency before linking.

JavaScript

Advertisement

Answer

Method 1: Using npm-link

Go to C:Usersuserprojectsreact-financial-charts in terminal:

JavaScript

Now, go to your project C:Usersuserprojectsmyproject:

JavaScript

Now, any changes to C:Usersuserprojectsreact-financial-charts will be reflected in C:Usersuserprojectsmyproject. Note that the link should be to the package name, not the directory name for that package.

Method 2: Saving local repo as npm-install

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement