score:0

The problem is that TypeScript will not try to parse or compile anything in your node_modules, it will assume all those dependencies are ready to be consumed. In order to be able to consume a TypeScript module you need to explicitly tell TypeScript to compile it. This though will require you to change your webpack.config.js. The steps to achieve this are outlined here.

I would discourage you from taking this road though - I would rather suggest looking into a monorepo setup (using yarn or lerna). In such setup you no longer need to set the dependency as file:..., which in turn allows you to:

  1. Open a terminal and start a build/watch task in your my-react-package
  2. Open another terminal and start a build/watch task in your my-react-app

Now The changes that you make to your my-react-package will be picked up by the watch task in your my-react-app

score:2

If you really don't want to rebuild every time, you can directly access the files like so:

import { thing } from "../my-react-package/src/thing"

However, what you probably want is to automatically recompile every time you make a change.

Your question didn't specify whether my-react-package uses webpack, so if it doesn't, you can watch the files being saved and automatically recompile via:

tsc -w

If you are using just raw webpack for your my-react-package, you can edit your webpack.config.js like so:

module.exports = {
  //...
  watch: true
};

This will tell webpack to automatically rebuild.

Alternatively, if you used create-react-app for my-react-package, you can install npm-watch:

npm i npm-watch

And then edit your package.json:

{
  // ...
  "devDependencies": {
    "npm-watch": "^0.1.8",
    "react-scripts": "0.9.5",
  },
  "dependencies": {
    "react": "^15.4.2",
    "react-dom": "^15.4.2"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject",
    "watch": "npm-watch"
  },
  "watch": {
    "build": "src/"
  }
}

Hope this helps.


Related Query

More Query from same tag