TypeScript - Object doesn't support property or method 'defineProperty'

13,224

Solution 1

According to the ES5 Compatibility table Object.defineProperty is supported in IE9 and above.

Support in IE8 is limited.

However, IE10 has a habit of running local and intranet pages in compatibility mode, even though the same pages run in normal mode over the Internet.

You can change this in the dialog in Tools > Compatibility View Settings (remove the "Display intranet sites in compatibility mode" option. You can also prevent this using a combination of the correct doctype:

<!DOCTYPE html> 

Or a user-agent compatibility tag, which will no longer be required (or supported) in IE11 and above.

<meta http-equiv="x-ua-compatible" content="IE=edge">

This must be the first tag within the <head> element.

Solution 2

Make sure that the first line of your HTML file is

<!doctype html>

This will prevent IE from going in compatibility mode and disable ES5 features.

Share:
13,224
7dino7
Author by

7dino7

Updated on June 14, 2022

Comments

  • 7dino7
    7dino7 almost 2 years

    I recently created a TypeScript project for a relatively complex simulation engine using Visual Studio which, by default, targeted ECMAScript 3 (ES3). I wanted to start using real properties in my TypeScript classes, so I updated my project file to target ES5, like so:

    <PropertyGroup Condition="'$(Configuration)' == 'Debug'">
      <TypeScriptTarget>ES5</TypeScriptTarget>
      <TypeScriptRemoveComments>false</TypeScriptRemoveComments>
      <TypeScriptSourceMap>true</TypeScriptSourceMap>
      <TypeScriptModuleKind>AMD</TypeScriptModuleKind>
    </PropertyGroup>
    <PropertyGroup Condition="'$(Configuration)' == 'Release'">
      <TypeScriptTarget>ES5</TypeScriptTarget>
      <TypeScriptRemoveComments>true</TypeScriptRemoveComments>
      <TypeScriptSourceMap>false</TypeScriptSourceMap>
      <TypeScriptModuleKind>AMD</TypeScriptModuleKind>
    </PropertyGroup>
    

    Now when I run my application in IE (v10), I get a run-time exception: "0x800a01b6 - JavaScript runtime error: Object doesn't support property or method 'defineProperty'". If I switch to launching my application with any other browser (e.g., Firefox, Chrome), it works as expected - no errors. I can't seem to find any reason why IE isn't working as expected. I found a website that confirmed that, in general, my IE browser supports 'defineProperty', so now I'm really baffled as to why it won't work during development. This is getting particularly critical since I can't debug my TypeScript code in VS. Any thoughts?

  • 7dino7
    7dino7 over 10 years
    Hmmm, I've had that all along in my 'default.htm' file, but it still apparently was launching in compatibility mode.
  • 7dino7
    7dino7 over 10 years
    Good to know. Thanks!
  • cchamberlain
    cchamberlain over 8 years
    Only problem is IE8 on Windows XP will not care about that tag so the only people its helping are people running IE>8 who were viewing in compatibility mode in the first place.
  • Brian Ogden
    Brian Ogden over 6 years
    @basarat I have <!doctype html> in my index.html and I am still getting this error in IE11