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

Add custom-server-typescript example (see #3694) #3838

Merged
merged 6 commits into from
Feb 22, 2018
Merged

Add custom-server-typescript example (see #3694) #3838

merged 6 commits into from
Feb 22, 2018

Conversation

retrixe
Copy link
Contributor

@retrixe retrixe commented Feb 18, 2018

Requested in #2744 as well.

@khuezy
Copy link
Contributor

khuezy commented Feb 19, 2018

I'm unable to use typescript syntax w/ any ts files under server:

SyntaxError: Unexpected token import

@retrixe
Copy link
Contributor Author

retrixe commented Feb 19, 2018

@khuezy just edited the example, hope it works now, was a mistake on my side with ts-node configuration.

@khuezy
Copy link
Contributor

khuezy commented Feb 19, 2018

@retrixe Thanks for getting this out!

I had to escape the " in the the nodemon.json file:
"ts": "ts-node --compilerOptions '{\"module\":\"commonjs\"}'"

@retrixe
Copy link
Contributor Author

retrixe commented Feb 19, 2018

@khuezy Fixed all issues with linting and the escaping issue, 😅 everything works now, thanks for the feedback :)

@khuezy
Copy link
Contributor

khuezy commented Feb 19, 2018

@retrixe I'm having trouble building.

I had to change the build script to:
"build": "next build && tsc server/**/*.ts --module commonjs --outDir lib --lib dom,es2015,es2016,es2017"

w/o the outDir it would compile the.js files in the server folder. It looks like it's not reading the tsconfig.json file.

@retrixe
Copy link
Contributor Author

retrixe commented Feb 20, 2018

Huh, I am unable to replicate on my side.
I am able to run the example without any issues?

I have switched the server to use import over require, and I am hoping that this PR is ready for merging.

@khuezy
Copy link
Contributor

khuezy commented Feb 21, 2018

in nodemon.json, I think you wanted to watch the .ts files instead of the .js?

@retrixe
Copy link
Contributor Author

retrixe commented Feb 22, 2018

Just fixed that, but it still doesn't seem that that is the issue.

@khuezy
Copy link
Contributor

khuezy commented Feb 22, 2018

@retrixe I finally figured out why my build was busted. For some reason, npm installed a really old version of chalk, which caused typescript to explode.

Everything is 👍 now. Thanks for adding this customer server ts support.

@timneutkens timneutkens merged commit 99fb191 into vercel:canary Feb 22, 2018
@kachkaev
Copy link
Contributor

kachkaev commented Mar 3, 2018

I just tried your example and it really helped me get a custom ts server! Two questions:

  • Do we need "jsx": "preserve", in tsconfig.json like in 97aef52?

  • Would not it be better to use production-server dir instead of lib? People may be using this directory for storing shared modules and this can create a glitch.

kachkaev added a commit to callthemonline/client-nextjs that referenced this pull request Mar 4, 2018
@retrixe
Copy link
Contributor Author

retrixe commented Mar 4, 2018

@kachkaev

  1. By default, the jsx value is preserve, so I do not believe we need to?.. I did not experience an issue with this myself when using VSCode so I cannot say.

  2. We can do this, but this can be individually customized as per people's needs and I think as an example we do not need to implement a different directory.

@kachkaev
Copy link
Contributor

kachkaev commented Mar 4, 2018

@retrixe

  1. I'm not sure why, but I had problems until I added preserve. Official docs in https://github.com/zeit/next-plugins/tree/master/packages/next-typescript#usage also mention jsx parameter.

  2. Some other Next.js examples do use lib for source files and it is often the case that people start new projects by combining a few examples together (that's what I was doing when I found your PR). I've already renamed lib to production-server in package.json and tsconfig.json in my new project – no big deal. However, this took some time and brain effort. People who are just starting with Next.js or TypeScript may get a bit confused and forget to rename something and then spend an hour on catching a bug they do not understand.

To summarise, I'll be happy to submit a PR that renames lib to production-server and also adds "jsx":"preserve". WDYT?

@retrixe
Copy link
Contributor Author

retrixe commented Mar 4, 2018

@kachkaev no problemo :)

timneutkens pushed a commit that referenced this pull request Mar 5, 2018
- Add "jsx": "preserve" to tsconfig.json
- Rename lib to production-server to remove incompatibility with other examples

Context: #3838 (comment) and below
@kachkaev
Copy link
Contributor

kachkaev commented Mar 7, 2018

One more tiny improvement: #3963

@lock lock bot locked as resolved and limited conversation to collaborators May 16, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants