6

I have a library which is written in typescript and is normally installed via npm. Currently I'm developing some app that requires it and I often need to make some changes in it as well. The ideal situation for me would be if I just could edit my library directly and see the changes in my app. I've tried with npm link but without success. How can use it with typescript?

1
  • Any chance you've found a way to do this? Commented Sep 19, 2024 at 11:09

1 Answer 1

1

You can npm link to your library but it needs to be compiled first.

Lets say you have project P that depends on library L, which are all local to you:

./repos
    ./P
        project.json
    ./L
        ./src
        ./dist
        project.json

The file /repos/L/project.json should have a entry main pointing to the main file of the library in dist. You have to compile the library (using tsc) to generate dist.

Then you do

$ cd repos/L
$ tsc      # or maybe npm run build
$ cd ../P
$ npm link ../L

And that's it.

Sign up to request clarification or add additional context in comments.

1 Comment

OK, but this way I would need to compile it every time I make a change in the library. I would like to work on .ts files directly. That's why I wrote that I couldn't get it working with npm link

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.