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

'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.


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.