0

I have an NPM library called 'example-lib' (built with Rollup) and a Vite React-TS project. I want to test 'example-lib' in my Vite project using npm link.

in library:

npm link

in project:

npm link @mjana/example-lib

However, I'm encountering an error stating 'Cannot find module' when importing components.

import { ComponentA } from "@mjana/example-lib"

I also tried using 'npm pack', which created a .tgz file. I then copied the file into my project directory and installed it using npm install. Surprisingly, this method works without any issues. Can you help me understand why 'npm link' isn't working for me?

Michal
  • 803
  • 2
  • 9
  • 26

1 Answers1

0

From the npm docs

If your linked package is scoped (see scope) your link command must include that scope, e.g.

npm link @myorg/privatepackage

In your case (in project):

npm link @mjana/example-lib
tom
  • 9,550
  • 6
  • 30
  • 49