Starting from the Typescript template, I managed to get the async chunk generation working (!). In addition to the previously mentioned steps, I had to add
"module": "nodenext"
in the tsconfig.json
file. With this setup, the chunk(s) are generated as intended for the (small) template. However, this change results in a change in the (default) value of moduleResolution
from node
to classic
, which causes tons of errors like,
[tsl] ERROR in /home/emher/Code/dash-leaflet/src/ts/components/FeatureGroup.tsx(3,58)
TS2792: Cannot find module 'react-leaflet'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?
in my larger project due to 3rd party library imports. If I switch back to node
, i.e. change my tsconfig.json
to[1],
"module": "nodenext",
"moduleResolution": "node",
The chunks are no longer generated . I guess I could try to adopt my project to use
modeResolution: "classic"
, but I really prefer modeResolution: "node"
. What do you think @Philippe ?
[1] There is a bug in the extract-meta.js
script when it parses the compiler options from the tsconfig.json
file. Instead of parsing the option into an option, it parses it into a string. It can be corrected using code like,
tsconfig.moduleResolution = tsconfig.moduleResolution == 'node' ? ts.ModuleResolutionKind.NodeJs : tsconfig.moduleResolution;
If you don’t add this fix, you’ll get an error like,
/home/emher/Code/tsconvert/node_modules/typescript/lib/typescript.js:2572
throw e;
^
Error: Debug Failure. Unexpected moduleResolution: node
at Object.resolveModuleName (/home/emher/Code/tsconvert/node_modules/typescript/lib/typescript.js:44046:37)
at loader_1 (/home/emher/Code/tsconvert/node_modules/typescript/lib/typescript.js:119377:117)
at loadWithModeAwareCache (/home/emher/Code/tsconvert/node_modules/typescript/lib/typescript.js:118997:46)
at actualResolveModuleNamesWorker (/home/emher/Code/tsconvert/node_modules/typescript/lib/typescript.js:119378:149)
at resolveModuleNamesWorker (/home/emher/Code/tsconvert/node_modules/typescript/lib/typescript.js:119667:26)
at resolveModuleNamesReusingOldState (/home/emher/Code/tsconvert/node_modules/typescript/lib/typescript.js:119765:24)
at processImportedModules (/home/emher/Code/tsconvert/node_modules/typescript/lib/typescript.js:121296:35)
at findSourceFileWorker (/home/emher/Code/tsconvert/node_modules/typescript/lib/typescript.js:121076:17)
at findSourceFile (/home/emher/Code/tsconvert/node_modules/typescript/lib/typescript.js:120922:26)
at /home/emher/Code/tsconvert/node_modules/typescript/lib/typescript.js:120871:85
Node.js v18.16.1
when you run npm run build:backends
.