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

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
chadarsenault opened this issue Sep 9, 2019 · 5 comments
Labels

Comments

@chadarsenault
Copy link

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

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

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

@reduardo7
Copy link

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

@dev-isho
Copy link

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

@rxliuli
Copy link

rxliuli commented Jun 6, 2021

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
Labels
Projects
None yet
Development

No branches or pull requests

5 participants