-
Notifications
You must be signed in to change notification settings - Fork 201
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
Problem with using typescript in server code #112
Comments
and I am using it in the server.ts like this `import PostController from './ServerCode/post.controller' app.use('/postUser', PostController); |
I am also facing this issue. Any solution for this? |
I had to import my routes with Can you try: const PostController = require('./ServerCode/post.controller');
app.use('/postUser', PostController); |
btw. you need also to export your class in In my route it looks like this: class Api {
constructor() {
this.app = express();
this.mountRoutes();
}
public app;
// Access this API route using {GET} and {POST} localhost:443/api/...
private mountRoutes(): void {
const router = express.Router();
router.post('/dummy', (req, res) => {
console.log(req.body);
});
module.exports = router;
}
}
export default new Api().app; |
I recommendation separate scripts for universal and backend |
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';
}
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 path = '/Post';
|
@ ./server.ts 73:0-57 74:21-35
`
The text was updated successfully, but these errors were encountered: