JayChase / angular2-highlight-js

highlight.js integration with Angular

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Using the library with npm link - Warning: "Cannot find source file '../src/highlight-js.module.ts'"

ernestbofill opened this issue · comments

I have an Angular component library that has angular2-highlight-js as a peerDependency.

At the same time I have an Angular website that uses the component library. During development, I use npm link to see any changes on the library applied to the website without re-installing the library.

In this scenario (when npm link is active), I see 3 compilation warnings on the website referring to angular2-highlight-js.

WARNING in C:/Projects/SPEAK3.Docs/code/Ng.Docs.Lib/~/angular2-highlight-js/lib/highlight-js.module.js
(Emitted value instead of an instance of Error) Cannot find source file '../src/highlight-js.module.ts': Error: Can't resolv
e '../src/highlight-js.module.ts' in 'C:\Projects\SPEAK3.Docs\code\Ng.Docs.Lib\node_modules\angular2-highlight-js\lib'
 @ C:/Projects/SPEAK3.Docs/code/Ng.Docs.Lib/dist/demo/demo.module.js 8:0-58
 @ C:/Projects/SPEAK3.Docs/code/Ng.Docs.Lib/dist/index.js
 @ ./src/app/app.module.ts
 @ ./src/app/index.ts
 @ ./src/main.ts
 @ multi webpack-dev-server/client?http://localhost:4322 ./src/main.ts

WARNING in C:/Projects/SPEAK3.Docs/code/Ng.Docs.Lib/~/angular2-highlight-js/lib/highlight-js-content.directive.js
(Emitted value instead of an instance of Error) Cannot find source file '../src/highlight-js-content.directive.ts': Error: C
an't resolve '../src/highlight-js-content.directive.ts' in 'C:\Projects\SPEAK3.Docs\code\Ng.Docs.Lib\node_modules\angular2-h
ighlight-js\lib'
 @ C:/Projects/SPEAK3.Docs/code/Ng.Docs.Lib/~/angular2-highlight-js/lib/highlight-js.module.js 4:39-82
 @ C:/Projects/SPEAK3.Docs/code/Ng.Docs.Lib/dist/demo/demo.module.js
 @ C:/Projects/SPEAK3.Docs/code/Ng.Docs.Lib/dist/index.js
 @ ./src/app/app.module.ts
 @ ./src/app/index.ts
 @ ./src/main.ts
 @ multi webpack-dev-server/client?http://localhost:4322 ./src/main.ts

WARNING in C:/Projects/SPEAK3.Docs/code/Ng.Docs.Lib/~/angular2-highlight-js/lib/highlight-js.service.js
(Emitted value instead of an instance of Error) Cannot find source file '../src/highlight-js.service.ts': Error: Can't resol
ve '../src/highlight-js.service.ts' in 'C:\Projects\SPEAK3.Docs\code\Ng.Docs.Lib\node_modules\angular2-highlight-js\lib'
 @ C:/Projects/SPEAK3.Docs/code/Ng.Docs.Lib/~/angular2-highlight-js/lib/highlight-js.module.js 25:29-62
 @ C:/Projects/SPEAK3.Docs/code/Ng.Docs.Lib/dist/demo/demo.module.js
 @ C:/Projects/SPEAK3.Docs/code/Ng.Docs.Lib/dist/index.js
 @ ./src/app/app.module.ts
 @ ./src/app/index.ts
 @ ./src/main.ts
 @ multi webpack-dev-server/client?http://localhost:4322 ./src/main.ts

As for how to configure the component library and the website to work with npm link, I followed this official Angular guide.

I currently use Angular 4.2.2

This is the relevant code from the component library referring to angular2-highlight-js:

// mylibrary.module.ts
@NgModule({
  imports: [
    CommonModule,
    HighlightJsModule
  ],
// etc...

// mylibrary.component.ts
@Component({
  selector: 'mylibrary-component',
  template: `
    <pre highlight-js-content><code><ng-content></ng-content></code></pre>
  `,
// etc...

Are you aware of the issue? Any solutions?