How to rename App.tsx?

I recently started a project with the blank typescript template and was following the tutorial to use jest for testing my app, when I ran into an issue.

When running yarn test, it would return the following error:

Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object

It took me a while, but I figured out that was because of the line import App from './App'; in App.test.tsx, which couldn’t tell the difference between app.json and App.tsx – so it defaulted to app.json.

So now, if I use in import App from './App.tsx';, yarn test will run just fine – except my editor (VSCode) is giving me an error because of the file extension: An import path cannot end with a '.ts' extension. Consider importing './App' instead.ts(2691).

Has anybody else encountered this problem? Is there a good way to satisfy typescript in this scenario?
Because I don’t think the app will work if I rename App.tsx to something else…

1 Like

Hi.

This might help:

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.