Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plugin-typescript not updating type checking on save in watch mode #186

Closed
David-Else opened this issue Jan 28, 2020 · 6 comments · Fixed by rollup/rollup#3388
Closed

plugin-typescript not updating type checking on save in watch mode #186

David-Else opened this issue Jan 28, 2020 · 6 comments · Fixed by rollup/rollup#3388

Comments

@David-Else
Copy link

David-Else commented Jan 28, 2020

  • Rollup Plugin Name: @rollup/plugin-typescript
  • Rollup Plugin Version:v3.0.0
  • Rollup Version:v1.30.1
  • Operating System (or Browser):Linux
  • Node Version:12

How Do We Reproduce?

create these files:
tsconfig.json

{
  "compilerOptions": {
    "target": "ES2019",
    "module": "ESNext",
    "sourceMap": true,
    "strict": true,
    "moduleResolution": "node",
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "resolveJsonModule": true
  },
  "include": ["src/**/*"]
}
// src/app.ts

export function example(): number {
  return 42;
}
// rollup.config.js

import typescript from '@rollup/plugin-typescript';

export default {
  input: 'src/app.ts',
  output: {
    dir: 'dist',
    format: 'esm'
  },
  plugins: [typescript()]
};

and run rollup -cw. It works, now change to and save:

// src/app.ts

export function example(): string {
  return 42;
}

It works, now gives type error... great... BUT, change it back to the correct type and it stays giving the same type error! It never re-read the file properly. The terminal blinks showing that it did re-read the file, but it is stuck in a cache or some kind of bug.

Expected Behavior

In watch mode, when you update a file it re-reads it and gives the correct TypeScript compiler error if needed.

Actual Behavior

In watch mode, when you update a file it re-reads it and gives the wrong TypeScript compiler error that refers to the file before it was updated.

@NotWoods
Copy link
Member

NotWoods commented Feb 1, 2020

I've found that if you change it back to the exact same text, it hits some cache in Rollup. Changing the code to something different but valid will fix the error, such as

// src/app.ts

export function example(): number {
  return 43;
}

This might need a fix in Rollup because I can't figure out how to detect this as a plugin. @lukastaegert any thoughts?

@shellscape shellscape changed the title @rollup/plugin-typescript v3 not updating type checking on save in watch mode plugin-typescript not updating type checking on save in watch mode Feb 3, 2020
@David-Else
Copy link
Author

@lukastaegert Did you get a chance to look into this? @NotWoods needs some feedback to continue. The extension is mostly broken for me until this is addressed, and it is so near perfect :)

@NotWoods
Copy link
Member

Quick fix for now is to change the text of the file after fixing the type error, which updates the cache.

@lukastaegert
Copy link
Member

The problem is that in case of error, the cache is not updated because no new cache object is created. Thus subsequent runs will use the outdated cache. This is a bug on Rollup side, but fixing it without completely disabling the cache in case of errors will require some thought. Essentially in case of errors, we still need to provide an updated cache. In the worst case we could attach it to the error object.

@lukastaegert
Copy link
Member

Created rollup/rollup#3386 to track on Rollup side.

@lukastaegert
Copy link
Member

Fix at rollup/rollup#3388

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants