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

TSError: ⨯ Unable to compile TypeScript #7

Closed
KatSick opened this issue Jul 15, 2017 · 11 comments
Closed

TSError: ⨯ Unable to compile TypeScript #7

KatSick opened this issue Jul 15, 2017 · 11 comments

Comments

@KatSick
Copy link

KatSick commented Jul 15, 2017

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
Copy link
Author

KatSick commented Jul 15, 2017

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
Copy link

felquis commented Jul 22, 2017

I fixed the problem with app.then, but then I found this issue, and it looks similar to the problem I'm facing microsoft/TypeScript#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
Copy link

patricknazar commented Aug 2, 2017

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

@jfmlima
Copy link

jfmlima commented Aug 5, 2017

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

@julianmnst
Copy link

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
Copy link

adrien2p commented Aug 13, 2017

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

@julianmnst
Copy link

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
Copy link

Itrulia commented Aug 17, 2017

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

@kamilmysliwiec
Copy link
Member

Hi,
Fixed.

@yeria-t
Copy link

yeria-t commented Mar 26, 2019

Do not forget to import the decorator ;)

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

@kenobi-io
Copy link

kenobi-io commented Nov 7, 2019

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

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

10 participants