nestjs / typescript-starter

Nest framework TypeScript starter :coffee:
https://nestjs.com
1.86k stars 1.04k forks source link

TSError: ⨯ Unable to compile TypeScript #7

Closed KatSick closed 7 years ago

KatSick commented 7 years ago
src/server.ts (5,5): Property 'listen' does not exist on type 'Promise<INestApplication>'. (2339)
    at getOutput (/Users/ochervak/Projects/nest-typescript-starter/node_modules/ts-node/src/index.ts:307:15)
    at /Users/ochervak/Projects/nest-typescript-starter/node_modules/ts-node/src/index.ts:336:16
    at Object.compile (/Users/ochervak/Projects/nest-typescript-starter/node_modules/ts-node/src/index.ts:496:11)
    at Module.m._compile (/Users/ochervak/Projects/nest-typescript-starter/node_modules/ts-node/src/index.ts:392:43)
    at Module._extensions..js (module.js:579:10)
    at Object.require.extensions.(anonymous function) [as .ts] (/Users/ochervak/Projects/nest-typescript-starter/node_modules/ts-node/src/index.ts:395:12)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
KatSick commented 7 years ago

Looks like you need to change server.ts with:

import { NestFactory } from '@nestjs/core';
import { ApplicationModule } from './modules/app.module';

const app = NestFactory.create(ApplicationModule);
app.then(instance => instance.listen(3000, () => console.log('Application is listening on port 3000')));
felquis commented 7 years ago

I fixed the problem with app.then, but then I found this issue, and it looks similar to the problem I'm facing https://github.com/Microsoft/TypeScript/issues/16772

➜  nest-typescript-starter git:(master) ✗ yarn start                    18:00:47
yarn start v0.24.5
$ node index.js 

/home/felquis/code/nest-typescript-starter/node_modules/ts-node/src/index.ts:316
          throw new TSError(formatDiagnostics(diagnosticList, cwd, ts, lineOffset))
                ^
TSError: ⨯ Unable to compile TypeScript
Cannot find type definition file for 'node'. (2688)
src/server.ts (1,29): Cannot find module '@nestjs/core'. (2307)
src/server.ts (2,35): Cannot find module './modules/app.module'. (2307)
    at getOutput (/home/felquis/code/nest-typescript-starter/node_modules/ts-node/src/index.ts:316:17)
    at /home/felquis/code/nest-typescript-starter/node_modules/ts-node/src/index.ts:347:18
    at Object.compile (/home/felquis/code/nest-typescript-starter/node_modules/ts-node/src/index.ts:474:19)
    at Module.m._compile (/home/felquis/code/nest-typescript-starter/node_modules/ts-node/src/index.ts:410:44)
    at Module._extensions..js (module.js:580:10)
    at Object.require.extensions.(anonymous function) [as .ts] (/home/felquis/code/nest-typescript-starter/node_modules/ts-node/src/index.ts:413:12)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Module.require (module.js:513:17)
error Command failed with exit code 1.
patricknazar commented 7 years ago

@felquis try yarn upgrade ts-node @types/node. Doing this solved it for me.

jfmlima commented 7 years ago

@felquis Doing this fixed my issues: npm install --save @types/node@latest ts-node@latest --force

julianmnst commented 7 years ago

Just tried @Jflima92 's solution with no success. Got this error instead:


 node index.js

SyntaxError: Unexpected token {
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:373:25)
    at Module._extensions..js (module.js:416:10)
    at Object.require.extensions.(anonymous function) [as .js] (/home/mpjm/Development/project/node_modules/ts-node/src/index.ts:384:14)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/home/mpjm/Development/project/node_modules/@nestjs/core/index.js:14:17)
    at Module._compile (module.js:409:26)

Any ideas? Where's @kamilmysliwiec ? I'm really excited about Nest.

adrien2p commented 7 years ago

Hey guys, You can also try this and give me your feedback starter kit implementation with sequelize and jwt

julianmnst commented 7 years ago

Ok I reinstalled the project, had the first problem and then did npm install --save @types/node@latest ts-node@latest without --force. Then I checked my package.json and saw that one package (don't remember wich) still had the * on it's version. npm suggested a version, I manually wrote it on package.json, npm install again and that solved it.

Itrulia commented 7 years ago

fixing ts-node@2.1.0 and typescript@2.2.1 fixes it for me.

kamilmysliwiec commented 7 years ago

Hi, Fixed.

yeria-t commented 5 years ago

Do not forget to import the decorator ;)

import {Headers} from '@nestjs/common';

kenobi-io commented 4 years ago

nodemon --config apps/api/nodemon-debug.json

[nodemon] 1.19.4 [nodemon] to restart at any time, enter rs [nodemon] watching dir(s): apps/api/src/*/ [nodemon] watching extensions: ts [nodemon] starting node --inspect-brk -r ts-node/register -r tsconfig-paths/register ./apps/api/src/main.ts Debugger listening on ws://127.0.0.1:9229/10fcf8fe-d379-4d87-9379-f03ca46ab57f For help, see: https://nodejs.org/en/docs/inspector Debugger attached src/main.ts:5 import * as tslib_1 from "tslib"; ^^^^^^

SyntaxError: Cannot use import statement outside a module at Module._compile (internal/modules/cjs/loader.js:892:18) at Module.m._compile (node_modules/ts-node/src/index.ts:493:23) at Module._extensions..js (internal/modules/cjs/loader.js:973:10) at Object.require.extensions. [as .ts] (node_modules/ts-node/src/index.ts:496:12) at Module.load (internal/modules/cjs/loader.js:812:32) at Function.Module._load (internal/modules/cjs/loader.js:724:14) at Function.Module.runMain (internal/modules/cjs/loader.js:1025:10) at internal/main/run_main_module.js:17:11