nest icon indicating copy to clipboard operation
nest copied to clipboard

TypeScript 2.4 Argument of type 'typeof AppModule' is not assignable to parameter of type 'NestModuleMetatype'.

Open cojack opened this issue 9 years ago • 7 comments

We have some problem with TypeScript 2.4 and his backward compatibility.

This is what I have now with typescript 2.4.1:

cojack:nest-test/ (develop*) $ npm start                                                                                                                                                                                                                                                                      [17:13:33]

> [email protected] start /home/cojack/Projects/nest-test
> node node_modules/.bin/ts-node src/index.ts


/home/cojack/Projects/nest-test/node_modules/ts-node/src/index.ts:296
        throw new TSError(formatDiagnostics(diagnosticList, cwd, ts, lineOffset))
              ^
TSError: ⨯ Unable to compile TypeScript
src/app/dispatcher.ts (18,34): Argument of type 'typeof AppModule' is not assignable to parameter of type 'NestModuleMetatype'.
  Type 'AppModule' has no properties in common with type 'NestModule'. (2345)
    at getOutput (/home/cojack/Projects/nest-test/node_modules/ts-node/src/index.ts:296:15)
    at /home/cojack/Projects/nest-test/node_modules/ts-node/src/index.ts:325:16
    at Object.compile (/home/cojack/Projects/nest-test/node_modules/ts-node/src/index.ts:479:11)
    at Module.m._compile (/home/cojack/Projects/nest-test/node_modules/ts-node/src/index.ts:379:43)
    at Module._extensions..js (module.js:580:10)
    at Object.require.extensions.(anonymous function) [as .ts] (/home/cojack/Projects/nest-test/node_modules/ts-node/src/index.ts:382:12)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.require (module.js:498:17)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: `node node_modules/.bin/ts-node src/index.ts`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/cojack/.npm/_logs/2017-07-07T15_13_38_900Z-debug.log

And the log output:

cojack:nest-test/ (develop*) $ cat /home/cojack/.npm/_logs/2017-07-07T15_13_38_900Z-debug.log                                                                                                                                                                                                                 [17:13:38]
0 info it worked if it ends with ok
1 verbose cli [ '/home/cojack/.nvm/versions/node/v7.3.0/bin/node',
1 verbose cli   '/home/cojack/.nvm/versions/node/v7.3.0/bin/npm',
1 verbose cli   'start' ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle [email protected]~prestart: [email protected]
6 silly lifecycle [email protected]~prestart: no script for prestart, continuing
7 info lifecycle [email protected]~start: [email protected]
8 verbose lifecycle [email protected]~start: unsafe-perm in lifecycle true
9 verbose lifecycle [email protected]~start: PATH: /home/cojack/.nvm/versions/node/v7.3.0/lib/node_modules/npm/bin/node-gyp-bin:/home/cojack/Projects/nest-test/node_modules/.bin:/home/cojack/.nvm/versions/node/v7.3.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
10 verbose lifecycle [email protected]~start: CWD: /home/cojack/Projects/nest-test
11 silly lifecycle [email protected]~start: Args: [ '-c', 'node node_modules/.bin/ts-node src/index.ts' ]
12 silly lifecycle [email protected]~start: Returned: code: 1  signal: null
13 info lifecycle [email protected]~start: Failed to exec start script
14 verbose stack Error: [email protected] start: `node node_modules/.bin/ts-node src/index.ts`
14 verbose stack Exit status 1
14 verbose stack     at EventEmitter.<anonymous> (/home/cojack/.nvm/versions/node/v7.3.0/lib/node_modules/npm/lib/utils/lifecycle.js:279:16)
14 verbose stack     at emitTwo (events.js:106:13)
14 verbose stack     at EventEmitter.emit (events.js:191:7)
14 verbose stack     at ChildProcess.<anonymous> (/home/cojack/.nvm/versions/node/v7.3.0/lib/node_modules/npm/lib/utils/spawn.js:40:14)
14 verbose stack     at emitTwo (events.js:106:13)
14 verbose stack     at ChildProcess.emit (events.js:191:7)
14 verbose stack     at maybeClose (internal/child_process.js:885:16)
14 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)
15 verbose pkgid [email protected]
16 verbose cwd /home/cojack/Projects/nest-test
17 verbose Linux 4.10.0-26-generic
18 verbose argv "/home/cojack/.nvm/versions/node/v7.3.0/bin/node" "/home/cojack/.nvm/versions/node/v7.3.0/bin/npm" "start"
19 verbose node v7.3.0
20 verbose npm  v4.6.1
21 error code ELIFECYCLE
22 error errno 1
23 error [email protected] start: `node node_modules/.bin/ts-node src/index.ts`
23 error Exit status 1
24 error Failed at the [email protected] start script.
24 error This is probably not a problem with npm. There is likely additional logging output above.
25 verbose exit [ 1, true ]

cojack avatar Jul 07 '17 15:07 cojack

https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#typescript-24

cojack avatar Jul 12 '17 18:07 cojack

Hey @cojack you just need to upgrade your ts-node dependency to 3.2.0 or higher ;-)

I've facing the issue and I developed the nest-cli update command in the v1.7.0 that fix the issue ;-)

thomrick avatar Jul 13 '17 06:07 thomrick

@ThomRick Im sorry but you're wrong. Check this:

cojack:private/ $ git clone https://github.com/kamilmysliwiec/nest.git ./nest-test
cojack:private/ $ cd nest-test 
cojack:nest-test/ (master) $ npm i
cojack:nest-test/ (master) $ node ./node_modules/.bin/tsc -v
Version 2.4.1
cojack:nest-test/ (master) $ npm i amqplib 
[email protected] /home/cojack/Projects/private/nest-test
└─┬ [email protected] 
  ├─┬ [email protected] 
  │ └── [email protected]  deduped
  ├── [email protected] 
  ├── [email protected] 
  └─┬ [email protected] 
    └── [email protected]

cojack:nest-test/ (master) $ rm gulpfile.js                                                                                                                                                                                                                                                                               
cojack:nest-test/ (master*) $ rm index.js
cojack:nest-test/ (master*) $ node ./node_modules/.bin/tsc
src/common/utils/decorators/shared.decorator.ts(8,5): error TS2322: Type '(target: FunctionConstructor) => typeof Type' is not assignable to type 'ClassDecorator'.
  Types of parameters 'target' and 'target' are incompatible.
    Type 'TFunction' is not assignable to type 'FunctionConstructor'.
      Type 'Function' is not assignable to type 'FunctionConstructor'.
        Type 'Function' provides no match for the signature '(...args: string[]): Function'.
src/core/pipes/pipes-context-creator.ts(9,14): error TS2415: Class 'PipesContextCreator' incorrectly extends base class 'ContextCreator'.
  Types of property 'createConcreteContext' are incompatible.
    Type '(metadata: PipeTransform[]) => Transform<any>[]' is not assignable to type '<T extends any[], R extends any[]>(metadata: T) => R'.
      Type 'Transform<any>[]' is not assignable to type 'R'.
src/core/router/router-exception-filters.ts(15,14): error TS2415: Class 'RouterExceptionFilters' incorrectly extends base class 'ContextCreator'.
  Types of property 'createConcreteContext' are incompatible.
    Type '(metadata: ExceptionFilter[]) => ExceptionFilterMetadata[]' is not assignable to type '<T extends any[], R extends any[]>(metadata: T) => R'.
      Type 'ExceptionFilterMetadata[]' is not assignable to type 'R'.
src/microservices/test/utils/client.decorator.spec.ts(10,17): error TS2559: Type '{ role: string; }' has no properties in common with type 'ClientMetadata'.
cojack:nest-test/ (master*) $ npm i [email protected]
[email protected] /home/cojack/Projects/private/nest-test
└── [email protected] 
cojack:nest-test/ (master*) $ node ./node_modules/.bin/tsc -v
Version 2.3.4
cojack:nest-test/ (master*) $ node ./node_modules/.bin/tsc

typescript in version 2.3.x compile code without any problem, it's not related to ts-node at all.

cojack avatar Jul 13 '17 07:07 cojack

Hey @cojack ok but that's not the same error in your second case...

In fact ts-node has to be upgraded to be used with typescript 2.4.0 But your second case is an other issue related to the typescript breaking changes on the Nest code

thomrick avatar Jul 13 '17 07:07 thomrick

Hey guys, It'd be fixed in the nearest release. @cojack thanks for reporting

kamilmysliwiec avatar Jul 16 '17 12:07 kamilmysliwiec

Hi, Should be fixed in the v4 :cake: Thanks

kamilmysliwiec avatar Sep 12 '17 15:09 kamilmysliwiec

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

lock[bot] avatar Sep 25 '19 11:09 lock[bot]