Using Nx for my Angular workspace, and noticed something, which raised my question. What's the purpose to use CommonJS modules in all tsconfig.spec.json files for libs? Checking Nx examples all libs don't have it, only apps have included "modules: "commonjs"
. Is it at all still needed, if in my case I'm working with modules purely on front-end side? Can't we rely on ES2015 (ES6) already in Angular/TypeScript projects for development? After all target is ES5 obviously, like so "target": "es5"
.
Especially, if CommonJS modules are specific only for tsconfig.spec.json files, i.e. for unit testing (Jest in my case). Removing "modules: "commonjs"
from my tsconfig.spec.json still makes all my unit tests passed, builded bundle is working fine, as well whilst checking during serving my application without any single error/warning.
After removing "modules: "commonjs"
, and then adding a new lib realised that's really useful. Without this Jest doesn't compiles, so it's required for Jest. It could be also checked cleaning Jest's cache (npx jest --clearCache
), and then trying to run it, it wouldn't compile.