I recently implemented serverside-rendering react app with code splitting using loadable-components
But it seems that loadable-components itself dependent on webpack, since loadable replaces jsonp_callback with its own reporter.
So what are the alternative options that we can use when using other bundlers like rollup, esbuild?
Do we have to manually walk through the react tree to pre configure which chunk is needed on which component unless there is no specific bundler targeted library like loadable-components when implementing code splitting on serverside rendering?
First, let us consult the compiler options reference:
The documentation for
typeRootsstates (emphasis mine):That second line is important: if you don't set
typeRootsthen tsc defaults to looking for directories undernode_modulescontaining@typesin their directory names.(The documentation doesn't say if it chooses
node_modulesbecause of themoduleResolutionparameter though. (I suspect I'd need to dig-intsc's source-code to find out for sure).)If you do set a value for
typeRootsthan that overrides tsc'snode_modules/**/@types*lookup logic and it will then only look in the specified directories.Not necessarily. You could also add your extra typings files' locations to the
pathsparameter and leave thetypeRootsparameter blank/un-set, which meanstscwill retain the "node_modules/@types-and-ancestor-walking behavior" but will see your.d.tsfiles just fine.This scenario is mentioned in this TypeScript GitHub thread: https://github.com/microsoft/TypeScript/issues/13581
So if you're asking about your specific local environment on your machine: and assuming that you're sticking with the normative, typical (I dare say mainstream) TypeScript working idioms (such as using
npm) then yes: you can remove thetypeRootsparameter becausetsc's (current) default behavior is to look fornode_modulesdirectories in the same location as yourtsconfig.json.(I understand that VS Code might also be pulling some strings behind-the-scenes to make
tsc"aware" of your project files and dependencies and for its language-server process - but that shouldn't matter as you'll noticetscshould work identically from the command-line outside of VS Code).If you're asking about the fundamental necessity of the
typeRootscompiler option, and supposing that you're thinking "that because practically everyone is usingnpmandnode_modulesthen why is the TypeScript team spending their time supporting unusual development configurations?"_ - well, for many very good reasons: tools shouldn't be dependent on other tools controlled by third-parties1: Consider the possibility that thenpmecosystem and/or NodeJS software could fall out of fashion overnight and then we'd be stuck withtsc's defaults still usingnode_moduleswhen everyone is rockin' some new cool JS environment: there'd be headaches for many years to resolve the mess (not that the JS ecosystem isn't a mess as it is).And there are many good reasons to not use
npmandnode_modules: people could be using TypeScript in an environment without internet access (think: secure software development, the defence industry, national secrets, etc) - those people in those situations might have a network share full of approved or known-trustworthy libraries that won't be usingnode_modules's naming convention - in which case if those people want to used.tsfiles they'll need to manually configure thetypeRootsparameter for themselves.1 I'm aware that
npm(which is legally separate from NodeJS, btw) is maintained by npm Inc, which is a subsidary of Microsoft (by way of being acquired by GitHub, also a Microsoft property), so havingtscdepend onnpmshouldn't be a problem - but that's a very recent thing: Microsoft only acquirednpm18 months ago in March 2020 - and Microsoft could very well spin-off npm Inc - or run it into the ground and everyone switches toyarn. So regardless of the end legal owners of whatever tooling is currently popular, you don't want unnecessary dependencies like that.