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

An compile error occured when create register instance repeatly #1168

Closed
mirages opened this issue Nov 28, 2020 · 4 comments
Closed

An compile error occured when create register instance repeatly #1168

mirages opened this issue Nov 28, 2020 · 4 comments
Milestone

Comments

@mirages
Copy link

mirages commented Nov 28, 2020

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
@blakeembrey
Copy link
Member

This is currently the expected behavior. It could be changed but there's always a possibility of double registration (e.g. if you had two ts-node instances we can't de-duplicate between them). A better solution is that you can ignore or only include certain paths with each instance registered.

@mirages
Copy link
Author

mirages commented Nov 29, 2020

@blakeembrey What's the meaning of " ignore or only include certain paths with each instance registered"? Could you give me more details or any demo?

@blakeembrey
Copy link
Member

There is documentation in the README here: https://github.com/TypeStrong/ts-node#cli-and-programmatic-options. It looks like there's a typo but scope and dir would work. I can make a PR to your test repo if that helps further.

@cspotcode
Copy link
Collaborator

The options' names have since changed, but scope and scopeDir are more clearly implemented and documented by #1367

@cspotcode cspotcode added this to the 10.1.0 milestone Jul 9, 2021
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