{"id":4054,"date":"2016-05-06T12:44:36","date_gmt":"2016-05-06T12:44:36","guid":{"rendered":"http:\/\/www.garysieling.com\/blog\/?p=4054"},"modified":"2016-05-06T12:44:36","modified_gmt":"2016-05-06T12:44:36","slug":"fixing-cannot-find-module-loading-jsx-typescript-modules-node","status":"publish","type":"post","link":"https:\/\/www.garysieling.com\/blog\/fixing-cannot-find-module-loading-jsx-typescript-modules-node\/","title":{"rendered":"Fixing &#8220;Cannot find module&#8221; loading JSX or Typescript modules in Node"},"content":{"rendered":"<p>If you start mixing Javascript and JSX or Typescript into a Node application, you can start to get module loading failures, even though you might be able to build all the files individually with Webpack:<\/p>\n<pre>\n> image-annotation@1.0.0 start D:\\projects\\image-annotation\n> node index\n\nmodule.js:440\n    throw err;\n    ^\n\nError: Cannot find module 'LectureSearchConfig'\n    at Function.Module._resolveFilename (module.js:438:15)\n    at Function.Module._load (module.js:386:25)\n    at Module.require (module.js:466:17)\n    at require (internal\/module.js:20:19)\n    at Object.<anonymous> (D:\\projects\\image-annotation\\src\\lecture_search\\LectureSearchApp.jsx:14:14)\n    at Module._compile (module.js:541:32)\n    at Object.require.extensions.(anonymous function) [as .jsx] (D:\\projects\\image-annotation\\node_modules\\node-jsx\\index.js:29:12)\n    at Module.load (module.js:456:32)\n    at tryModuleLoad (module.js:415:12)\n    at Function.Module._load (module.js:407:3)\n<\/pre>\n<p>The basic problem is that even though you&#8217;ve told Webpack about these file types, Node doesn&#8217;t know about them. You need to decide if this is something you want &#8211; for development, it makes sense to allow Node to compile things while it runs, because you can automatically reload the page this way, but in a production environment you may prefer the built files.<\/p>\n<p>To make node aware, you need to add these. If you&#8217;re only using one, you obviously only need that item. It&#8217;s funny to see how these are completely different naming schemes, which is a downside of the decentralized nature of Javascript development.<\/p>\n<pre lang=\"javascript\">\nrequire(\"node-jsx\").install({extension: \".jsx\"});\nrequire(\"ts-node\").register();\n<\/pre>\n<p>Obviously you also need to install these:<\/p>\n<pre lang=\"bash\">\nnpm install node-jsx --save\nnpm install ts-node --save\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Fixing module loading errors in Node, when using new languages<\/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":[9],"tags":[302,387,557,592],"aioseo_notices":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/4054"}],"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=4054"}],"version-history":[{"count":0,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/4054\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/media?parent=4054"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/categories?post=4054"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/tags?post=4054"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}