Closed KatSick closed 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')));
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.
@felquis try yarn upgrade ts-node @types/node
. Doing this solved it for me.
@felquis Doing this fixed my issues:
npm install --save @types/node@latest ts-node@latest --force
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.
Hey guys, You can also try this and give me your feedback starter kit implementation with sequelize and jwt
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.
fixing ts-node@2.1.0
and typescript@2.2.1
fixes it for me.
Hi, Fixed.
Do not forget to import the decorator ;)
import {Headers} from '@nestjs/common';
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.