'const' can only be used in a .ts file error

I used create-react-app for my react app, which ive done many times before but right away I noticed I was getting an error whenever I used const within my files.

[ts]: ‘const’ can only be used in a .ts file

is the exact error I am getting. Anyone know how to fix this?

Which editor are you seeing this in? Did you install any TypeScript packages? Do you have your project in a repository that you can share?

edit: I just realized how old this post is. I have become the necroposter.

1 Like

It can literally be anything. You have to post either the stack trace, or tell us which line is causing this error. Screenshot your console and so we can guide you.

For anyone from the Future:

Most likely you are trying to create a constant in the class component. Move your const out of a component or change class component to function component