Using TypeScript with Cordova? Read this.

I cover this tip and much more in my Pluralsight course, but repeated here in text for you. This tip also applies if you are using Electron on Linux.

If you are using Cordova with TypeScript, here is a tip that’ll save you hours of head scratching. This is especially if you are planning on reusing web based code with cordova.

The issue is, Cordova, Android, requires case specific file naming. So, “myFile.js” and “MyFile.js” are different. Now, as it happens, TypeScript tries to infer the JavaScript file case naming based on what you specify in the input filename.

So, MyFile.ts will yield myFile.js.

BUT — if you are importing the MyFile.ts as follows

import MyFileComponent from ‘./myFile.ts’ ..

guess what! .. the generated file is no myFile.js — EVEN THOUGH — the input was MyFile.ts

Wow so sucky!

Luckily there is help. In your tsconfig.json just write “forceConsistentCasingInFileNames”: true .. and the TypeScript compiler will allow you to shoot yourself in the foot, but will at least warn you with errors. This will prevent case specific errors from happening when you move from Web –> Cordova, or Cordova (iOS) –> Cordova (Android).