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

Webpack watch missing changed files #697

Closed
KnisterPeter opened this issue Dec 19, 2017 · 6 comments
Closed

Webpack watch missing changed files #697

KnisterPeter opened this issue Dec 19, 2017 · 6 comments

Comments

@KnisterPeter
Copy link
Contributor

Expected Behaviour

Detect all changed files used in a compilation

Actual Behaviour

Some files are missing in some cases

Steps to Reproduce the Problem

https://github.com/KnisterPeter/webpack-multi-app-test

Run npm run watch and change src/core/plugin.ts.
It is expected that src/sub/index.tsx fails afterswards.

Location of a Minimal Repository that Demonstrates the Issue.

https://github.com/KnisterPeter/webpack-multi-app-test

The problem is within the watch-run. Changed files are filtered here. Maybe its deeper and webpack does not set correct timestamps.

https://github.com/TypeStrong/ts-loader/blob/master/src/watch-run.ts#L25

@johnnyreilly
Copy link
Member

Thanks for the minimal repro repo - that's always appreciated. I suspect the issue is that the file in question is interfaces only; i.e. it produces no JS output which means file changes result in no changes to the JS output. As far as webpack is concerned, there wasn't any output before; there isn't now either.

There's not an immediately obvious solution to this. However, I'm hopeful that when the new watch API changes get merged (#685) this may resolve the issue.

@KnisterPeter
Copy link
Contributor Author

Right now there is at least the defintion file updated. Wouldn't it this idea be possible:

  1. Filter the list of files as it is done now but exclude .d.ts files.
  2. Always handle .d.ts files as if they where touched.

@KnisterPeter
Copy link
Contributor Author

As well, right now it does not even help to touch those files and there is no hook into the loader to trigger it manually (I know what was updated and when).

@KnisterPeter
Copy link
Contributor Author

To give some more info here, this is the content of the times object in watch-run.ts:

{
  '/x/webpack-test/src/sub/app.tsx': 1513681246518,
  '/x/webpack-test/src/sub/index.tsx': 1513691257828,
  '/x/webpack-test/src/sub/package.json': 1513679868805,
  '/x/webpack-test/src/sub/tsconfig.json': 1513679868805,
  '/x/webpack-test/dist/core/index.d.ts': 1,
  '/x/webpack-test/dist/core/plugin.d.ts': 1,
  '/x/webpack-test/node_modules/@types/node/index.d.ts': 1,
  '/x/webpack-test/node_modules/@types/node/inspector.d.ts': 1,
  '/x/webpack-test/node_modules/@types/react-dom/index.d.ts': 1,
  '/x/webpack-test/node_modules/@types/react/global.d.ts': 1,
  '/x/webpack-test/node_modules/@types/react/index.d.ts': 1,
  '/x/webpack-test/node_modules/typescript/lib/lib.d.ts': 1
}

Everything with a timestamp of 1 and not 'living' in node_modules could be seen as updated. These files are all part of the current compilation and therefore part of the ts Program.

@johnnyreilly
Copy link
Member

I'm open to PRs that fix the issue - I'd be happy to advise along the way

KnisterPeter pushed a commit to KnisterPeter/ts-loader that referenced this issue Dec 19, 2017
If a project depends on custom definition files, meaning not the ones in node_modules, then it should consider them changed when webpack triggers a watch-run.
Since webpack doesn't know about definition files, we use the one detected by the languageService which should be more accurate anyway.

Closes TypeStrong#697
@ZSkycat
Copy link

ZSkycat commented Oct 25, 2018

I have encountered the same problem. The reason for this problem is not just a pure types file, but a ts file that is not actually used. That is, only type or interface is imported.

This problem can be solved by import './type';

Don't worry. The webpack production mode can removes empty modules and tree shaking. This won't have extra code being packaged. 😄

my case

type.ts

export interface InterfaceA {
    a1: number;
    a2: string;
}

export function test() {
    console.log('test');
}

index.ts

import { InterfaceA } from './type';
// import './type';

export function app(value: InterfaceA) {
    console.log(value.a1.toFixed(0));
    console.log(value.a2.trim());
}

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

No branches or pull requests

3 participants