A compound having the formula: or a pharmaceutically acceptable salt thereof, wherein: A is a 5 or 6-membered heteroarylene group; W is N or -CH-; X is N or -C(R 3)-; R 1 is selected from-(C 1 -C 6 alkylene)-aryl, -(C 1 -C 6 alkylene)-(5 or 6-membered heteroaryl), -(C 1 -C 6 alkylene)-O-aryl, -(C 1 -C 6 alkylene)-O-(5 or 6-membered heteroaryl) and C 3 -C 6 cycloalkyl, wherein any aryl, heteroaryl or C 3 -C 6 cycloalkyl group can be optionally substituted with up to four R 7 groups, which can be the same or different, and wherein said C 3 -C 6 cycloalkyl group can be fused to a benzene ring and said fused benzene ring can be optionally substituted with up to four R 7 groups, which can be the same or different; each occurrence of R 2 is independently selected from H, C 1 -C 6 alkyl, -OH, -O-(C 1 -C 6 alkyl) and -(C 1 -C 6 alkylene)-O-(C 1 -C 6 alkyl); R 3 is selected from H, C 1 -C 6 alkyl, C 1 -C 6 hydroxyalkyl and -CN, or R 3 and an R 2 group, together with the carbon atoms to which they are attached, can combine to form a cyclopropyl ring; R 4 is H, or R 4 and an R 2 group, can join to form a group selected from -CH 2 -CH 2 -CH 2 -, - C -O-CH 2 -, -CH 2 -O-CH 2 - and -CH 2 -N(R 8)-CH 2 -; R 5 is -NH(R 6), 5 or 6-membered monocyclic heterocycloalkyl or 9 or 10-membered bicyclic heterocycloalkyl, wherein said 5 or 6-membered monocyclic heterocycloalkyl group can optionally form a spirocycle with a C 3 -C 6 cycloalkyl group or another 5 or 6-membered monocyclic heterocycloalkyl group, and wherein said 5 or 6-membered monocyclic heterocycloalkyl group and said 9 or 10-membered bicyclic heterocycloalkyl group can be optionally substituted on one or more ring carbon atoms with up to four R 7 groups, which can be the same or different, and wherein a ring carbon atom of a 5 or 6-membered monocyclic heterocycloalkyl group may be functionalized as a carbonyl group R 6 is C 1 -C 6 alkyl or 5 or 6-membered heteroaryl, wherein said C 1 -C 6 alkyl group is optionally substituted with 1 or 2 groups, each independently being NH 2 or halo, and wherein said 5 or 6-membered heteroaryl group can be optionally substituted with up to four R 7 groups; each occurrence of R 7 is independently selected from C 1 -C 6 alkyl, 5 or 6-membered heterocycloalkyl, C 1 -C 6 hydroxyalkyl, C 1 -C 6 haloalkyl, halo, -CN, -N(R 8) 2, -CH 2 N(R 8) 2, -OR 8, - C OR 8, -SR 8, -S 2 R 8 and -C N(R 8) 2, wherein said 5 or 6-membered heterocycloalkyl group can be optionally substituted with a group selected from C 1 -C 6 alkyl, halo, C 1 -C 6 hydroxyalkyl, C 1 -C 6 haloalkyl, halo, -CN, -N(R 8) 2 and -OR 8; and each occurrence of R 8 is independently H or C 1 -C 6 alkyl. A is a 5 or 6-membered heteroarylene group; W is N or -CH-; X is N or -C(R 3)-; R 1 is selected from-(C 1 -C 6 alkylene)-aryl, -(C 1 -C 6 alkylene)-(5 or 6-membered heteroaryl), -(C 1 -C 6 alkylene)-O-aryl, -(C 1 -C 6 alkylene)-O-(5 or 6-membered heteroaryl) and C 3 -C 6 cycloalkyl, wherein any aryl, heteroaryl or C 3 -C 6 cycloalkyl group can be optionally substituted with up to four R 7 groups, which can be the same or different, and wherein said C 3 -C 6 cycloalkyl group can be fused to a benzene ring and said fused benzene ring can be optionally substituted with up to four R 7 groups, which can be the same or different; each occurrence of R 2 is independently selected from H, C 1 -C 6 alkyl, -OH, -O-(C 1 -C 6 alkyl) and -(C 1 -C 6 alkylene)-O-(C 1 -C 6 alkyl); R 3 is selected from H, C 1 -C 6 alkyl, C 1 -C 6 hydroxyalkyl and -CN, or R 3 and an R 2 group, together with the carbon atoms to which they are attached, can combine to form a cyclopropyl ring; R 4 is H, or R 4 and an R 2 group, can join to form a group selected from -CH 2 -CH 2 -CH 2 -, - C -O-CH 2 -, -CH 2 -O-CH 2 - and -CH 2 -N(R 8)-CH 2 -; R 5 is -NH(R 6), 5 or 6-membered monocyclic heterocycloalkyl or 9 or 10-membered bicyclic heterocycloalkyl, wherein said 5 or 6-membered monocyclic heterocycloalkyl group can optionally form a spirocycle with a C 3 -C 6 cycloalkyl group or another 5 or 6-membered monocyclic heterocycloalkyl group, and wherein said 5 or 6-membered monocyclic heterocycloalkyl group and said 9 or 10-membered bicyclic heterocycloalkyl group can be optionally substituted on one or more ring carbon atoms with up to four R 7 groups, which can be the same or different, and wherein a ring carbon atom of a 5 or 6-membered monocyclic heterocycloalkyl group may be functionalized as a carbonyl group R 6 is C 1 -C 6 alkyl or 5 or 6-membered heteroaryl, wherein said C 1 -C 6 alkyl group is optionally substituted with 1 or 2 groups, each independently being NH 2 or halo, and wherein said 5 or 6-membered heteroaryl group can be optionally substituted with up to four R 7 groups; each occurrence of R 7 is independently selected from C 1 -C 6 alkyl, 5 or 6-membered heterocycloalkyl, C 1 -C 6 hydroxyalkyl, C 1 -C 6 haloalkyl, halo, -CN, -N(R 8) 2, -CH 2 N(R 8) 2, -OR 8, - C OR 8, -SR 8, -S 2 R 8 and -C N(R 8) 2, wherein said 5 or 6-membered heterocycloalkyl group can be optionally substituted with a group selected from C 1 -C 6 alkyl, halo, C 1 -C 6 hydroxyalkyl, C 1 -C 6 haloalkyl, halo, -CN, -N(R 8) 2 and -OR 8; and each occurrence of R 8 is independently H or C 1 -C 6 alkyl.