I am trying to modernize a project that had old school javascript code in which vendor js libraries are included directly into HTML. The first step I am taking is to use NPM to install libraries into node_modules directory, get typescript installed into the project, start using JS modules with import statement.
Unfortunately, I am getting an error that I have no idea to fix for the last few days. The typescript compiler keeps complaining that it cannot find modules. For instance, when importing range
from rxjs
, this error message appears(though I’ve clearly installed it via npm and the library exists in node_modules directory):
Build:Cannot find module ‘rxjs’. Did you mean to set the ‘moduleResolution’ option to ‘nodenext’, or to add aliases to the ‘paths’ option?
I have looked around answers from stackover and couldnt find a way to solve this issue. Does anyone have any idea how to get visual studio’s typescript compiler to locate where modules are installed? Thx.
This is how the tsconfig.json file looks like for me, changing the moduleresolution
from node
to nodenext
does not fix it:
{
"compilerOptions": {
"module": "ES2015",
"noImplicitAny": false,
"removeComments": true,
"preserveConstEnums": true,
"sourceMap": true,
"moduleResolution": "Node"
},
"files": [
"app/main.ts"
]
}