Moodle, TypeScript, and CDK

We moved our Moodle workloads to AWS in 2020, using CDK to manage the infrastructure. It’s one of our oldest such deployments and has been stable for years. I was nonplussed, to say the least, when, I attempted to update our development environment to the Moodle 4.1 beta and received almost 400 TypeScript errors like the one below:

1
public/lib/editor/tiny/js/tinymce/tinymce.d.ts(7,10): error TS2304: Cannot find name 'Range'.

It took me a few minutes to realize what I was actually looking at. We install the Moodle core code in the public directory of the project. CDK’s npm run build command wraps tsc, the typescript compiler, and it was looking at TypeScript modules inside the Moodle directory. Thanks to a helpful hint from Stackoverflow, I modified tsconfig.json to exclude public:

1
2
3
4
5
6
7
8
9

{
...
"exclude": [
"node_modules",
"cdk.out",
"public"
]
}

That’s not appropriate in a number of use cases, but in this specific one it resolved my issue and I was back in business.