Skip to content

An compile error occured when create register instance repeatly #1168

@mirages

Description

@mirages

Expected Behavior

No error occured, and use the new register instance compile the .ts file once when create a new register instance to cover an old one, the old one may be created by third-party library(e.g. karma cli).

The reason for create a new register is that, I want to use a special RegisterOptions for .test.ts files.

Actual Behavior

By debugging the source code, I found that if create two register, the require.extensions[.ts] handler was nested registration by registerExtensions function twice. And the .ts file was compiled twice, the old register's output as the new register's input, then some error occured, like below:

TSError:  Unable to compile TypeScript:
error TS7022: '__awaiter' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.
2 var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
......

Steps to reproduce the problem

  1. First, create a test.ts for test the problem.
  2. Then, create a index.js, and create two register instances directly in order to simplify the problem, then require the test.ts file.
  3. Finally, run the node index.js command.

Minimal reproduction

ts-node-test

Specifications

  • ts-node version: 9.0.0
  • node version: 13.9.0
  • TypeScript version: 4.0.5
  • Operating system and version: win7-64bit

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions