Skip to content

Strange "Cannot find module" error when using with TSLint and the no-unused-variable rule #74

@pelotom

Description

@pelotom

This is a very weird bug which took me hours to whittle down to a minimal example, so I hope it's of use. Steps to reproduce:

  1.  git clone https://github.com/pelotom/fork-ts-checker-bug
     cd fork-ts-checker-bug
     npm install
     npm start
    
  2. Everything should compile fine on the first run. Now open the file foo.ts, add a newline or some other innocuous change, and save it.
  3. Now there is an error in a completely different file:
    ERROR in /Users/tom/code/fork-ts-checker-bug/index.ts
    (1,25): Cannot find module 'moment'.
    

What the hey!?

Some observations:

  • Undoing the change has no effect; the error remains. However modifying index.ts and saving it fixes the problem somehow.
  • Killing the watch process and restarting fixes the problem; first builds always work
  • The problem only occurs with the no-unused-variable TSLint rule enabled
  • If another library besidesmoment is imported in index.ts, it may or may not exhibit the problem. For example, typestyle exhibits the problem but rxjs doesn't. I'm not sure what the commonality is among packages that run afoul of this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions