{"id":4733,"date":"2016-07-19T01:54:30","date_gmt":"2016-07-19T01:54:30","guid":{"rendered":"http:\/\/www.garysieling.com\/blog\/?p=4733"},"modified":"2016-07-19T01:54:30","modified_gmt":"2016-07-19T01:54:30","slug":"fixing-error-typeerror-define-not-function-typescript","status":"publish","type":"post","link":"https:\/\/www.garysieling.com\/blog\/fixing-error-typeerror-define-not-function-typescript\/","title":{"rendered":"Fixing error &#8220;TypeError: define is not a function&#8221; with TypeScript"},"content":{"rendered":"<p>If you try to run TypeScript programs on the command line (or tests) you can get this irritating and cryptic error:<\/p>\n<pre>\nTypeError: define is not a function\n<\/pre>\n<p>Typically this comes with a very large stack trace.<\/p>\n<p>What this actually means is that your files aren&#8217;t being compiled into the correct module format. You want this, in tsconfig.json (if you don&#8217;t have one, you can do &#8220;tsc &#8211;init&#8221;).<\/p>\n<pre lang=\"javascript\">\n{\n    \"compilerOptions\": {\n        \"module\": \"commonjs\",\n        \"target\": \"es6\",\n        \"noImplicitAny\": false,\n        \"sourceMap\": false,\n        \"outDir\": \"dist\"\n    },\n    \"exclude\": [\n        \"node_modules\",\n        \"typings\"\n    ]\n}\n<\/pre>\n<p>The key here is to switch to commonjs.<\/p>\n<p>Note also that I&#8217;ve added outDir &#8211; this puts all the compiled Javascript in a separate folder, where it&#8217;s easier to delete and look at. If you take this verbatim, you&#8217;ll want to delete the old Javascript files you made with tsc, or things will get confusing.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Fixing module loading errors in TypeScript<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[4],"tags":[302,557],"aioseo_notices":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/4733"}],"collection":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/comments?post=4733"}],"version-history":[{"count":0,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/4733\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/media?parent=4733"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/categories?post=4733"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/tags?post=4733"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}