0

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:

C:\Users\user\projects\react-financial-charts // fresh checkout from Github
C:\Users\user\projects\myproject // my project

Inside of my project, my package.json contains:

"dependencies": {
 "react-financial-charts": "file:C:/Users/user/projects/react-financial-charts"
}

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:

Module not found: Error: Can't resolve 'react-financial-charts' in 'C:\Users\user\projects\myproject\src\App'

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:

npm link ../react-financial charts
npm install ../react-financial charts
npm install --save ../react-financial charts

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.

cd react-financial-charts
npm link
cd ../myproject
npm link react-financial-charts
Jase
  • 1,025
  • 1
  • 9
  • 34
  • 1
    This might help to you https://stackoverflow.com/questions/15806241/how-to-specify-local-modules-as-npm-package-dependencies – Yushan Jul 11 '21 at 09:17

1 Answers1

3

Method 1: Using npm-link

Go to C:\Users\user\projects\react-financial-charts in terminal:

npm link

Now, go to your project C:\Users\user\projects\myproject:

npm link react-financial-charts

Now, any changes to C:\Users\user\projects\react-financial-charts will be reflected in C:\Users\user\projects\myproject. 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

npm install --save ../path/to/mymodule
Jishan Shaikh
  • 1,572
  • 2
  • 13
  • 31