One of my colleagues updated our front-end watch/build system with TypeScript support. Which is great, except it wasn’t working for me… but it was for him and another colleague. We all used a clean install of the system and the dependencies. The only difference was that they run Windows, and I use Ubuntu.
The new build script uses jQuery and the
@types/jquery package. The following TypeScript import works on Windows:
import $ from 'jQuery';
… but gives the following error on Ubuntu:
Error TS2307: Cannot find module 'jQuery' or its corresponding type declarations.
We tried setting the reference path to make sure the type declaration could be found:
/// <reference path="../node_modules/@types/jquery/index.d.ts" />
But unfortunately, that didn’t solve the problem.
After some debugging I had the sense to double-check the actual module path and realized that the issue was the fact that on Windows, paths are case insenstive; that is,
node_modules/jQuery/ is ‘the same’ as
node_modules/jquery/. However, on Linux, this is not the case; paths are case sensitive, and so
tsc couldn’t find the module.
The fix was easy; simply import jQuery with a lower-case q:
import $ from 'jquery';
Photo by Hitarth Jadhav from Pexels.