question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problem with using typescript in server code

See original GitHub issue

when I want to use type script as server code I get Error

my .ts code


` import * as express from ‘express’;

class PostController { public router; public path = ‘/Post’;

constructor() {
    this.router = express.Router();
    this.initRoutes();
}

public initRoutes() {
    this.router.get(this.path, this.getPosts);
}

getPosts(request: express.Request, response: express.Response) {
    response.send('Posts list')
}

}

export default PostController; `

and when I wun " npm run ssr" I get this error can you please help me

` ERROR in ./ServerCode/post.controller.ts 4:11 Module parse failed: Unexpected token (4:11) You may need an appropriate loader to handle this file type, currently no loader s are configured to process this file. See https://webpack.js.org/concepts#loade rs | | class PostController {

public router;

| public path = ‘/Post’; | @ ./server.ts 73:0-57 74:21-35 `

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
hofa77commented, Aug 6, 2019

and I am using it in the server.ts like this

`import PostController from ‘./ServerCode/post.controller’

app.use(‘/postUser’, PostController); `

0reactions
Gornivcommented, Aug 15, 2019

I recommendation separate scripts for universal and backend

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeScript Server Error (4.7.3) - Quick Fix... not working #50162
I have started VS Code by using the command: "Developer: Reload With Extensions Disabled". It's a newly generated project for which I have...
Read more >
Common TypeScript module problems and how to solve them
Enabling the compiler module resolution tracing in TypeScript can provide insight in diagnosing and solving problems.
Read more >
The common misconception about TypeScript
First, you have to understand why we need TypeScript when coding with JavaScript is enough for most of the use-cases. People use TypeScript...
Read more >
A Complete Guide to Using TypeScript in Node.js - Better Stack
TypeScript is a superset of JavaScript that brings static typing capabilities to the language. Since its introduction in 2011, it has steadily gained ......
Read more >
TypeScript tutorial with Visual Studio Code
The TypeScript language service has a powerful set of diagnostics to find common coding issues. For example, it can analyze your source code...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found