64

First of all, I've already seen the other posts about error TS1005. Same error code, but totally different.

A simple let x: number; will generate the error TS1005 during compilation. It's not about a missing semicolon as what the error message says, but the compiler does not recognize the let keyword. I read that maybe because of an outdated compiler.

Here's my typescript version installed using npm install -g typescript

  • TypeScript version: 2.5.2
  • Compiler (tsc) version: 1.0.3.0

Maybe somebody can help?

Nicolás Alarcón Rapela
  • 2,714
  • 1
  • 18
  • 29
StockUberflow
  • 643
  • 1
  • 5
  • 4
  • 1
    Possible duplicate of [TypeScript error: ';' expected when using "let" keyword](https://stackoverflow.com/questions/36899390/typescript-error-expected-when-using-let-keyword) – jonrsharpe Sep 25 '17 at 06:47
  • No. This is an error from Typescript because npm installs the wrong version. I opened [an issue about it](https://github.com/Microsoft/TypeScript/issues/21510). @StockUberflow Please support it. – Yairopro Jan 31 '18 at 14:10

16 Answers16

87

Your installation is wrong; you are using a very old compiler version (1.0.3.0).

tsc --version should return a version of 2.5.2.

Check where that old compiler is located using: which tsc (or where tsc) and remove it.

Try uninstalling the "global" typescript

npm uninstall -g typescript

Installing as part of a local dev dependency of your project

npm install typescript --save-dev

Execute it from the root of your project

./node_modules/.bin/tsc
Bruno Grieder
  • 28,128
  • 8
  • 69
  • 101
  • 5
    Hi sir, solved it. Thank you. The key is `which tsc` or `where tsc`. Found out there was another version of tsc in C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\. I just removed the old one from the path. – StockUberflow Sep 25 '17 at 07:37
  • 1
    Opened an [issue on github](https://github.com/Microsoft/TypeScript/issues/21510) about it. – Yairopro Jan 31 '18 at 14:10
  • 2
    I was using a slightly older version of tsc which led to not existing issues. I updated the global tsc and now it is okay. – Seagull Aug 28 '18 at 12:51
  • 3
    This worked awesome. I was using `npx tsc ` to compile. Weird that `npx` would use an outdated version? – colefner Jul 04 '19 at 05:49
  • @StockUberflow I can't find any other version nor can I find the Microsoft SDKs folder? Will you help me after 6 years? – Ali Bin Naseer Aug 07 '23 at 10:57
20

On Windows you can have in your PATH

PATH = ...;C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\; ...

remove it from PATH env, then

npm install -g typescript@latest

it worked for me to solve the

"TypeScript error TS1005: ';' expected"

See also how to update TypeScript to latest version with npm?

venergiac
  • 7,469
  • 2
  • 48
  • 70
7

You don't have the last version of typescript.

Running :

npm install -g typescript

npm checks if tsc command is already installed.

And it might be, by another software like Visual Studio. If so, npm doesn't override it. So you have to remove the previous deprecated tsc installed command.

Run where tsc to know its bin location. It should be in C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\ in windows. Once found, delete the folder, and re-run npm install -g typescript. This should now install the last version of typescript.

Henry
  • 1,311
  • 1
  • 9
  • 26
Yairopro
  • 9,084
  • 6
  • 44
  • 51
4

I faced the same error. After banging my head for half an hour, I found one Romeo bracket hanging around without his Juliet LOL...!(the opening and closing brackets were mismatching) Please check all your brackets to avoid such errors.

3

The issue was in my code.

In large code base, issue was not clear.

A simplified code is below:

Bad:

 collection.insertMany(
    [[],
    function (err, result) {
    }
 );

Good:

collection.insertMany(
    [],
    function (err, result) {
    }
 );

That is, the first one has [[], instead of normal array []

TS error was not clear enough, and it showed error in the last line with } );

Hope this helps.

Manohar Reddy Poreddy
  • 25,399
  • 9
  • 157
  • 140
2

I had today a similar error message. What was peculiar is that it did not break the Application. It was running smoothly but the command prompt (Windows machine) indicated there was an error. I did not update the Typescript version but found another culprit. It turned there was a tiny omission of symbol - closing ")", which I believe The Typescript is compensating for. Just for reference the code is the following:

[new Object('First Characteristic','Second Characteristic',
'Third Characteristic'*] 

* notice here the ending ")" is missing.

Once brought back no more issues on the command prompt!

CyberMessiah
  • 1,084
  • 11
  • 14
1
  • Remove C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0 directory.

  • Now run :

    npm install -g typescript 
    

    this will install the latest version and then re-try.

Nicolás Alarcón Rapela
  • 2,714
  • 1
  • 18
  • 29
1

Just try to without changing anything npm install rxjs@X.X.X X.X.X is your current version

celikz
  • 101
  • 2
  • 13
0

I was injecting service like this:

private messageShowService MessageShowService

instead of:

private messageShowService: MessageShowService

and that was the reason of error, despite nothing related with ',' was there.

user1892777
  • 131
  • 2
  • 7
0

If you're getting error TS1005: 'finally' expected., it means you forgot to implement catch after try. Generally, it means the syntax you attempted to use was incorrect.

user-12410035
  • 277
  • 4
  • 2
0

Stupid issue with minor mistake;

i was trying

const quizType = computed(() => rootState.quizzes.quiz

const res = await noAuthApi.getQuizzes(quizType)

and the issue was, i missed the closing bracket. it should be like

const quizType = computed(() => rootState.quizzes.quiz)

const res = await noAuthApi.getQuizzes(quizType)
Seetpal singh
  • 3,505
  • 1
  • 15
  • 12
0

Verify extension of file. File containing tsx should have .tsx extension.

Yuvraj Patil
  • 7,944
  • 5
  • 56
  • 56
0

in my case I'd the 'function' keyword. I'd to remove it.

Bad:

export class CustomValidators {

static function myFunc(x: string) { console.log(x) } }

Good:

export class CustomValidators {

static myFunc(x: string) { console.log(x) } }

RT.
  • 435
  • 2
  • 9
  • 25
0

I got this error

In my case the Import type supported on typescript version 3.8 or above, but I install lower version of ngx-tour-core that doesn't contain Import type and problem solved.

tanbir254
  • 1
  • 2
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Sumit Sharma May 27 '22 at 14:01
0

Mine was solved with this.

// TS1005
constructor(
  @Inject('USER_SERVICE') private readonly 
  userService: UsersService,
) { }

// No Error
constructor(
  @Inject('USER_SERVICE') private readonly userService: UsersService,
) { }
Baris Senyerli
  • 642
  • 7
  • 13
-1

There may be a conflict with both of the packages "tsc" & "typescript" due to the fact that they both use the same command tsc index.ts

tsc is deprecated, hence you should only use typescript:

> npm install -g typescript

> tsc ./index.ts

Idanref
  • 169
  • 1
  • 1
  • 9