Skip to content
This repository has been archived by the owner on Apr 3, 2024. It is now read-only.

Gatsby develop crashes on type errors #36

Closed
eXaminator opened this issue Feb 1, 2020 · 6 comments
Closed

Gatsby develop crashes on type errors #36

eXaminator opened this issue Feb 1, 2020 · 6 comments

Comments

@eXaminator
Copy link

I am just converting a rather small gatsby project to typescript using this awesome plugin. It seems to be a lot better than the default typescript plugin.

But I have come across one quite annoying behavior: When running gatsby develop it seems to crash after some type errors occured. Here is an example:

ERROR #98123  WEBPACK

Generating SSR bundle failed

ERROR in /....../src/templates/DogTemplate.tsx(73,33):
TS2605: JSX element type '{} | null' is not a constructor function for JSX elements.
  undefined

not finished Generating image thumbnails - 61.696s


0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'run', 'develop' ]
————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
16 pages                                             In Progress                                             bsf-website
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! bsf-website@1.0.0 develop: `gatsby develop`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the bsf-website@1.0.0 develop script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/xxx/.npm/_logs/2020-02-01T22_09_00_221Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! bsf-website@1.0.0 start: `npm run develop`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the bsf-website@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/xxx/.npm/_logs/2020-02-01T22_09_00_248Z-debug.log

This can be quite annoying as type errors are expected during development and the dev server should simply display those errors on a console (ideally in browser and terminal) without crashing.

Is this a known behavior or is it something I'm doing wrong on my end?

@d4rekanguok
Copy link
Owner

Thank you for the kind words!

It indeed shouldn't crash the main process & only report the error in terminal. Does it happen consistently for you? Sorry about the inconvenience.

@eXaminator
Copy link
Author

I'm afraid I can't reproduce it right now. It seems to work for the moment. I guess it has to do with the nature of the specific error, as it seems to crash if the error happens while SSR is happening. At least that's how I interpret above error. Sadly I don't have a lot of knowledge of how gatsby handles SSR exactly, so it's hard for me to debug or reproduce.

The errors kept happening while I was converting the JS codebase to TS. Maybe it had something to do with the specific errors I got while converting and having a mixed codebase?

I'll keep my eyes open to see if it happens again and if I can manage to find out the circumstances that lead to the crash

You can close the issue for now if you want, I'm happy to come back to it later IF it happens again and we could reopen it then.

@d4rekanguok
Copy link
Owner

I've just updated the default fork-checker plugin (#64) so it show error on the browser + might prevent crashes, please upgrade (2.4.0) and try it out! Will close this issue for now, please feel free to reopen if the crash happens continuously.

@olee
Copy link
Contributor

olee commented Mar 6, 2020

I have this issue when using gatsby-plugin-graphql-codegen with gatsby-plugin-typescript.
Once I write an invalid query somewhere, it will crash the whole cli:

 ERROR

    GraphQLDocumentError: Cannot query field "mdx" on type "Query".
        at E:/dev/.../site/src/templates/article.tsx:2:5

  AggregateError: GraphQLDocumentError: Cannot query field "mdx" on type "Query".

  - article.tsx:2
    E:/dev/React/one-suedwest-website/new/site/src/templates/article.tsx:2:5

  - index.cjs.js:431 Object.checkValidationErrors
    [site]/[@graphql-toolkit]/common/index.cjs.js:431:15

  - index.cjs.js:89 Object.codegen
    [site]/[@graphql-codegen]/core/index.cjs.js:89:16

@olee
Copy link
Contributor

olee commented Mar 6, 2020

I found out this is caused by the call to reporter.panic(err) here.

Also see this: gatsbyjs/gatsby#13179

@d4rekanguok d4rekanguok reopened this Mar 7, 2020
@d4rekanguok
Copy link
Owner

d4rekanguok commented Mar 7, 2020

@olee thanks so much for identifying the cause!

Comes to think about it, codegen should never crash its process. If you have time to spare, would you like to send a PR to change reporter.panic to reporter.warn?

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

No branches or pull requests

3 participants