andersonbalves
andersonbalves

Reputation: 319

Preserve Symlinks in Angular Libraries

I have a problem.

I'm trying to make a Angular 8 Library using ng-cli, but i can't preserve symlinks from my external application using npm link.

I've tried to add this on my angular.json:

    "build": {
      "builder": "@angular-devkit/build-ng-packagr:build",
      "options": {
        "preserveSymlinks": true,
        "tsConfig": "projects/button/tsconfig.lib.json",
        "project": "projects/button/ng-package.json"
      }
    }, 

but got:

"Schema validation failed with the following errors: Data path ""
should NOT have additional properties(preserveSymlinks)."

I found that it doesn't work for libraries.

Then I tried to add this to my tsconfig.lib.json:

 "angularCompilerOptions": {
    "annotateForClosureCompiler": true,
    "skipTemplateCodegen": true,
    "strictMetadataEmit": true,
    "fullTemplateTypeCheck": true,
    "strictInjectionParameters": true,
    "enableResourceInlining": true,
    "preserveSymlinks": true
  }

And nothing happend.

I searched here for a solution, but couldn't find anything like it.

How can I make it?

Thank you!

Upvotes: 24

Views: 44502

Answers (4)

SebLeich
SebLeich

Reputation: 1

For me, it worked to add the following code section to the ng-packagr library's tsconfig.json file:

{
  "compilerOptions": {
    "paths": {
      "@angular/*": [ "./node_modules/@angular/*" ]
    }
  }
}

Setup: Angular 14, ng-packagr 14.2.2

Upvotes: 0

Dariusz Filipiak
Dariusz Filipiak

Reputation: 3124

In angular 13... this allowed me to use symlinks with ng serve

enter image description here

Upvotes: 5

user14989617
user14989617

Reputation: 31

Adding this to my tsconfig.lib.json worked for me:

 "angularCompilerOptions": {
    "preserveSymlinks": true
  }

Are you sure you are not overriding this property in tsconfig.lib.prod.json and making a production build?

Upvotes: 3

Armando Perez
Armando Perez

Reputation: 1215

I believe you need to add the preserveSymlinks option in the angular.json located at the project that will consume your library. For instance, I was testing locally, and I added it in my architect -> build -> options.

You will able to find more info here: https://dev.to/nieds/getting-started-building-component-libraries-with-angular-cli-4ncj

Hope this helps!

Upvotes: 35

Related Questions