Skip to content

Typescript plugin fails to compile the entry point when there is at least one invalid TypeScript file somewhere is the working directory #1652

Closed
@ericmorand

Description

@ericmorand

Expected Behavior

In the reproduction repository, we find 3 TS files:

  • src/index.ts, the entry point
  • src/valid.ts, imported by the entry point
  • src/invalid.ts, containing non valid TypeScript syntax and imported by neither src/index.ts or src/valid.ts

When executing rollup on src/index.ts, the build should be successful since the src/invalid.ts file is not imported.

Actual Behavior

The build is unsuccessful, and the error suggests that src/invalid.ts is syntax-checked by the plugin even though it is not part of the dependency graph of the entry point:

$ npx rollup -i src/index.ts -p @rollup/plugin-typescript
npm WARN cli npm v10.2.4 does not support Node.js v16.20.2. This version of npm supports the following node versions: `^18.17.0 || >=20.5.0`. You can find the latest version at https://nodejs.org/.

src/index.ts → stdout...
var foo = 5;

console.log(foo);
(!) Plugin typescript: @rollup/plugin-typescript TS2304: Cannot find name 'foo'.
src/invalid.ts: (1:1)

1 foo
  ~~~

Additional Information

Note that the behaviour of tsc is correct in that regard:

$ tsc src/index.ts

No error is emitted and src/index.ts and src/valid.ts are successfully compiled.

So the error is coming from the plugin, not from the TypeScript compiler.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions