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

[1.0] gatsby-plugin-typescript fails without tsconfig.json #840

Closed
aendra-rininsland opened this issue Apr 22, 2017 · 11 comments
Closed

[1.0] gatsby-plugin-typescript fails without tsconfig.json #840

aendra-rininsland opened this issue Apr 22, 2017 · 11 comments
Assignees

Comments

@aendra-rininsland
Copy link

From the docs it seemed as if all that needed to be done to get gatsby-plugin-typescript working is to install the dependencies and add an entry to gatsby-config.js — however, if you don't also create a tsconfig.json file, gatsby develop throws the following:

WARNING in ./pages/index.tsx
Module build failed: error while parsing tsconfig.json
@ ./pages (coffee|cjsx|ts|tsx|jsx|js|md|rmd|mkdn?|mdwn|mdown|markdown|litcoffee|ipynb|html|json|yaml|toml)$
ERROR in error TS18002: The 'files' list in config file 'tsconfig.json' is empty.

A workaround is running: ./node_modules/.bin/tsc --init in the root of a project.

It'd be cool if one wasn't necessary and all TypeScript config could just be done in gatsby-config.js.

@KyleAMathews
Copy link
Contributor

Thanks for bring this up! It seems a sensible solution would be for the plugin to check if tsconfig.json exists early in starting Gatsby and if it doesn't, to run the init command. How's that sound? I say this with knowing very little about Typescript :-) but yeah, I can see someone starting a new Gatsby project and thinking, "hey! It'd be fun to try Typescript" and they'd be confused upon adding this plugin and things not working out-of-the-box.

/cc @noahlange and @fabien0102

@fabien0102
Copy link
Contributor

I'm use to have a tsconfig.json so I not really aware on this issue, but I understand that It can be cool to have a default one :)

@Aendrew I'm actually working on a gatsby-starter (including typescript), If you want to test/contribute, your are welcome 😃

@fabien0102 fabien0102 self-assigned this Apr 23, 2017
@noahlange
Copy link
Contributor

Whoops. Thanks for picking this up, @fabien0102. I have a tsconfig.json file in all of the TS projects I work on, so I just never ran into this.

You may need to update the webpack config.

@fabien0102
Copy link
Contributor

I will try something like that ^^

@fabien0102
Copy link
Contributor

The tsconfig.json file controls TypeScript-related options so that your IDE, the tsc command, and this loader all share the same options.

From tsloader docs

I tried some configurations but you can't pass files options (so it's failed to find any files). And it's important to have tsconfig.json for your IDE ;)

I will just update the doc (and add ts-loader into dependencies)

@KyleAMathews
Copy link
Contributor

KyleAMathews commented Apr 23, 2017 via email

@fabien0102
Copy link
Contributor

@KyleAMathews Just overkill for instant ^^

@KyleAMathews
Copy link
Contributor

Cool :-) and it looks like people need a fairly custom tsconfig.json file anyways for Gatsby so pushing them that way is necessary right?

@fabien0102
Copy link
Contributor

tsconfig.json needs to be on root directory (for your IDE), and it's cool for add libs/rules easily. I just said that a simple copy/past of the example file into README.md should be good enough for instant. (the must to have should be a gatsby plugin add typescript but we are not on the state for instant ^^)

@aendra-rininsland
Copy link
Author

Apologies for the delay getting back to this — totally valid point about having tsconfig.json for IDE tooling. Improving the documentation is the right way to go, nicely done @KyleAMathews with #848!

@KyleAMathews
Copy link
Contributor

Thanks! Though that's been @fabien0102 who's been tending the typescript docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants