I’m just cutting my teeth on my first “real” React app for work, and I think I’m doing something wrong– please let me know!
I’ve created and built/packaged a reusable component “AccountSelector“. The build files are happily existing in ../account-selector/dist. The subdir that account-selector lives in shouldn’t be important.
I haven’t deployed this app to npm or an internal npm server; I want to “just use it” locally in a different React project. Following the npm link instructions, I’ve run npm link in the base account-selector directory.
The separate ReactJS app that I want to reuse AccountSelector in is in a different directory branch, let’s call it ../foobar.
As per the instructions, I’ve run npm link account-selector in the foobar directory, and the link is happily made.
However, what is unhappy is App.js when trying to import the account-selector component: After a bit of trying / testing, I’ve found the only way to successfully import the linked AccountSelector component is:
import AccountSelector from ‘../node_modules/account-selector/dist/index’
I would hope that the linked component should be accessible by
import {AccountSelector} from “account-selector”
but when I do so, my IDE (WebStorm) instantly underlines the word “account-selector” with a “Module is not installed” error.
I’ve linked, re-linked, created the link in the dist directory, and nothing seems to work.
Am I (hopefully!) doing something wrong, or is this “just how it is” when using React with a npm link? Do I need to hack foobar’s package.json file to “help it” discover the account-selector component?
Thanks in advance!
submitted by /u/perandtim
[link] [comments]