javascriptnpmyarnpkgckeditor5ckeditor-plugin

yarn installing a local npm package such that the local package uses node_modules of main project (ckeditor-duplicated-modules error)


In my MainProject I'm trying to install a local version of a ckeditor-5 plugin PeteCkPlugin created with the ckeditor5 package generator.

I tried using the yarn link in my local PeteCkPlugin root dir, then yarn link @PeteSpace/PeteCkPlugin in the MainProject root dir, but got a Usage Error: Invalid destination '@PeteSpace/PeteCkPlugin'; Can't link the project to itself error.

I've also tried using the yarn package.json resolutions field:

{
  ...,
  "resolutions": { 
    "@PeteSpace/PeteCkPlugin": "link:/path/to/project/PeteSpace/PeteCkPlugin" 
  },"
  ...
}

which successfully installs the package, but MainProject then fails due to an "Uncaught CKEditorError: ckeditor-duplicated-modules Read more: https://ckeditor.com/docs/ckeditor5/latest/support/error-codes.html#error-ckeditor-duplicated-modules" error, as I think the local PeteCkPlugin package is using it's own PeteCkPackage/node_modules/ckeditor package, rather than the shared MainProject/node_modules/ckeditor package...

I've also tried the portal: in place of link: in the resolutions value above"...

I can't publish the package yet as it's private and I'm not yet in the right npm org.

Happy to hear any ideas that could help, I definitely don't yet understand symlinking and what's happening under the hood with yarn and npm.


Solution

  • I've had similar problems with yarn link over time and resorted to using yalc instead, which has worked flawlessly every time.

    The process is quite simple:

    1. Install Yalc globally
    volta install yalc # or `npm i -g yalc` if you don't use volta
    
    1. Publish your dependency
    yalc publish # run from dependency root after build process
    
    1. Link the dependency
    yalc link # run from the root of your main project
    

    You can also subscribe and autopublish on changes from your dependency.

    For more information see the official readme.