JulianG
JulianG

Reputation: 4765

"[ts] Unterminated regular expression literal."

I'm getting this error in an almost empty React component:

[ts] Unterminated regular expression literal.

import * as React from 'react';

export default class EmptyComponent extends React.Component {

    render() {

        return (
            <p>Hello</p>
        );
    }
}

I don't know what I'm doing wrong!

Upvotes: 69

Views: 40532

Answers (5)

Pulasthi Buddika
Pulasthi Buddika

Reputation: 1

In case if anybody got this error while developing a regex, make sure to wrap your regex with forward slashes.

Regex Delimiters (/).

Upvotes: 0

Bobby
Bobby

Reputation: 377

I'm using WebStorm. The file is a .tsx file and turned out that after I close the file and re-open the file again, the issue is gone itself.

Upvotes: 1

ey dee ey em
ey dee ey em

Reputation: 8613

So my case was a bit unique. I had the same error message. but everything got fix after I restarted the build process (e.g. in this case I was working with storybook, so npm run storybook). The symptom was that, even I changed my file name to be .tsx the error still reporting the same file as .ts. That reminded me that I changed the file name when the build is already watching and running. That's when I decided restart the build command and wolaa! everything fixed itself.

Sometime its just that --- "Have you turn it off and on again?"

Upvotes: 8

philthathril
philthathril

Reputation: 506

Just in case someone else runs across this and has named their file appropriately, re-inspect your regex to make sure you haven't accidentally created an invalid regex. For example, mine looked like:

/^https?:\/\/

and it should have been:

/^https?:\/\//
             ^ left this lil' guy off

You can also use an online regex tool to make sure you've created a valid regex.

Upvotes: 4

JulianG
JulianG

Reputation: 4765

It turns out I was using the .ts file extension instead of .tsx

Make sure your component file extension is .tsx (if you're using Typescript) or .jsx (if you're using Javascript).

Upvotes: 226

Related Questions