Skip to content

Re-exported const enums break emit in watch mode #376

@smphhh

Description

@smphhh

Given

bar.ts:

export const enum BarEnum {
    Bar = 1
};

foo.ts:

export { BarEnum } from './bar';

app.ts:

import { BarEnum } from './foo';
console.log(BarEnum.Bar);

the emit for app.ts in the initial build looks like the following:

"use strict";
console.log(1 /* Bar */);

After changing bar.ts to

export const enum BarEnum {
    Bar = 2
};

no modules will be rebuild. The expected output after the change would be

"use strict";
console.log(2 /* Bar */);

This is because ts-loader currently only adds the direct dependencies of modules as dependencies to webpack. Because bar.ts is not a direct dependency of app.ts, app.ts will not be rebuild when bar.ts changes.

For semantic errors the deeper dependencies are handled in the after-compile hook, but this doesn't help in cases like const enums where the actual emit can depend on deeper dependencies.

I believe awesome-typescript-loader does add all actual dependencies of a module as webpack dependencies recursively, which I think is the only way to handle these (relatively rare) cases correctly.

I'll post a pull-request with a test showcasing this error.

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