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

TypeScript JSX support for _document #3511

Closed
jatsrt opened this issue Dec 28, 2017 · 6 comments · Fixed by #3578
Closed

TypeScript JSX support for _document #3511

jatsrt opened this issue Dec 28, 2017 · 6 comments · Fixed by #3578
Assignees

Comments

@jatsrt
Copy link

jatsrt commented Dec 28, 2017

If using TypeScript with "preserve" which generates "jsx" files, you cannot define _document as the framework looks for a _document.js and not _document.jsx.

@jatsrt
Copy link
Author

jatsrt commented Dec 28, 2017

To be fair, this would not work if using ".jsx" without typescript also.

@corydeppen
Copy link

You can try using react-native for the jsx option as the example app in this repo illustrates. Per the TS doc, this will output files with the js extension as Next expects.

@jatsrt
Copy link
Author

jatsrt commented Dec 30, 2017

@corydeppen thanks, already doing that. But in canary "jsx" support is one of the items. Might make sense to extend that so it supports JSX for anything in pages.

@corydeppen
Copy link

You mentioned you were using preserve, which is a different option than react-native. Do you need to support jsx files and can't switch to using "jsx": "react-native" in tsconfig.json?

I'm on next@4.2.1 and _document seems to work fine with typescript@2.6.2. I've added a _document.tsx file in my pages directory (which gets compiled to .js), included a link tag for a global style sheet, and the page renders with the expected markup.

I apologize if I'm misunderstanding the issue.

@jatsrt
Copy link
Author

jatsrt commented Jan 2, 2018

I was using "react-native" with 4.2.1, but with the release of 4.3.0 "JSX support" was added. So, switched to "preserve" as it makes more sense to use "preserve" than "react-native".

"preserve" will produce a _document.jsx instead of _docuemnt.js. Since 4.3 supports JSX, it would make sense that it would support _document.jsx as part of that, therefore allowing users to use "preserve" without confusion or later needing to switch back to "react-native".

@timneutkens
Copy link
Member

Yeah, this is a bug, good catch! Will add a label for now and fix it later on 👍

@timneutkens timneutkens self-assigned this Jan 2, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Jan 30, 2019
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 a pull request may close this issue.

3 participants