question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

WARNING: '__read' is imported from external module 'tslib' but never used

See original GitHub issue

Type of Issue

[ X] Bug Report
[ ] Feature Request

Description

Trying to build the package and getting the following error warning

WARNING: ‘__read’ is imported from external module ‘tslib’ but never used

Not usre where it’s been exported, but it’s not from my project.

Note, I’ve just update from Angular 8 to 9.0.1

How To Reproduce

ng build

Expected Behaviour

Success with no warning

Version Information

$ node_modules/.bin/ng-packagr --version
ng-packagr: x.y.z
@angular/*: x.y.z
typescript: x.y.z
rxjs: x.y.z
node: x.y.z
npm/yarn: x.y.z

Please include all version numbers that might be relevant, e.g. third-party libraries

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:24
  • Comments:14 (2 by maintainers)

github_iconTop GitHub Comments

19reactions
multimike77commented, Mar 3, 2020

Something which is probably related to this problem as well. On my library project I was getting many errors like
WARNING: 'OnInit', 'OnDestroy', 'AfterContentInit' are imported from external module '@angular/core' but never used apart from having the __read is imported... erorr as described above as well.

After experimenting a bit, I found out something interesting. I could manage to make the warning about OnInit, OnDestroy, etc. disappear by separating the import statements in two:

  • one which only contains imports relevant for type declarations
  • all other imports, which are also used for values etc.

For example:

import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnDestroy, OnInit } from '@angular/core';

@Component({
  selector: 'lib-my-lib',
  template: `
    <p>
      my-lib works!
    </p>
  `,
  styles: [],
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class MyLibComponent implements OnInit, OnDestroy {

  constructor(
      private cd: ChangeDetectorRef
  ) { }

  ngOnInit(): void {
    this.cd.markForCheck();
  }

  ngOnDestroy(): void {
  }

}

this compiles with warning
WARNING: 'OnDestroy' and 'OnInit' are imported from external module '@angular/core' but never used.
But when changing the imports to be like

import { ChangeDetectionStrategy, Component, OnDestroy, OnInit } from '@angular/core';
import { ChangeDetectorRef } from '@angular/core';

compilation works fine without any warnings.

So somehow the compiler is no able to optimize/rewrite the import statements so that only relevant imports are kept.

Probably related to: https://github.com/angular/angular/issues/21280

4reactions
rafa-ascommented, Apr 24, 2020

Some news here?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Module never used warning while building Angular 9 library
I tried to find the root cause of it but I couldn't. There is one github issue related to this but there was...
Read more >
@rollup/plugin-typescript - npm
Start using @rollup/plugin-typescript in your project by running ... Create a rollup.config.js configuration file and import the plugin:.
Read more >
TSConfig Reference - Docs on every TSConfig option
A module file is a file that has imports and/or exports. Without this flag, using an export from a UMD module requires an...
Read more >
Introduction - rollup.js
Introduction. Overview. Rollup is a module bundler for JavaScript which compiles small pieces of code into something larger and more complex, ...
Read more >
Understanding TypeScript Configuration Options
By using it, you can structure your TypeScript project into smaller pieces. ... This syntax requires an imported helper but module 'tslib' cannot...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found