Skip to content

error TS7022: '__importDefault' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. #883

Closed

Description

@chadarsenault

OS: Windows 10 64
Environment: node v10.14.2, ts-node v8.3.0, typescript v3.6.2

I receive this error only while running ts-node as the loader, but not while compiling with typescript directly. I've attached the contents of my project's root\api dir, C:\www\node-framework\api for inspection. The only two files currently being touched by typescript should be C:\www\node-framework\api\src\framework.ts and C:\www\node-framework\api\src\app.ts

Full error:

$ node_modules/.bin/ts-node --require ts-node/register ./src/framework.ts

C:\www\node-framework\api\node_modules\ts-node\src\index.ts:245
    return new TSError(diagnosticText, diagnosticCodes)
           ^
TSError: ⨯ Unable to compile TypeScript:
src/framework.ts:2:5 - error TS7022: '__importDefault' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

2 var __importDefault = (this && this.__importDefault) || function (mod) {
      ~~~~~~~~~~~~~~~
src/framework.ts:2:67 - error TS7006: Parameter 'mod' implicitly has an 'any' type.

2 var __importDefault = (this && this.__importDefault) || function (mod) {
                                                                    ~~~

    at createTSError (C:\www\node-framework\api\node_modules\ts-node\src\index.ts:245:12)
    at reportTSError (C:\www\node-framework\api\node_modules\ts-node\src\index.ts:249:19)
    at getOutput (C:\www\node-framework\api\node_modules\ts-node\src\index.ts:362:34)
    at Object.compile (C:\www\node-framework\api\node_modules\ts-node\src\index.ts:395:32)
    at Module.m._compile (C:\www\node-framework\api\node_modules\ts-node\src\index.ts:473:43)
    at Module.m._compile (C:\www\node-framework\api\node_modules\ts-node\src\index.ts:473:23)
    at Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at require.extensions.(anonymous function) (C:\www\node-framework\api\node_modules\ts-node\src\index.ts:476:12)
    at Object.require.extensions.(anonymous function) [as .ts] (C:\www\node-framework\api\node_modules\ts-node\src\index.ts:476:12)
[www_node-framework_api.zip](https://github.com/TypeStrong/ts-node/files/3588384/www_node-framework_api.zip)

    at Module.load (internal/modules/cjs/loader.js:599:32)

Activity

  1. blakeembrey commented on Sep 10, 2019

    @blakeembrey
    Member

    It looks like you've registered ts-node twice, so it's compiling your TypeScript then again with the output from TypeScript.

  2. blakeembrey commented on Sep 10, 2019

    @blakeembrey
    Member

    It actually says so in your CLI: ts-node --require ts-node/register - use one or the other, not both at the same time.

  3. reduardo7 commented on Jan 14, 2020

    @reduardo7

    Like @blakeembrey said, you should use node_modules/.bin/ts-node ./src/framework.ts or node --require ts-node/register ./src/framework.ts

  4. dev-isho commented on Feb 24, 2020

    @dev-isho

    It looks like you've registered ts-node twice, so it's compiling your TypeScript then again with the output from TypeScript.

    Woo Thanks it works

  5. rxliuli commented on Jun 6, 2021

    @rxliuli

    Is there a way to check whether ts-node is used to run the code in the code? such as environment variables

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions