Add below lines to tsconfig.json
"compilerOptions": {//...rest parameters"baseUrl": "./","paths": {"tslib" : ["path/to/node_modules/tslib/tslib.d.ts"]},
In my case, tslib was already installed and i was seeing this error only for 1 component while everything else was working fine - build and functionality.I just restarted my vscode and it vanished.So, try that if the error is still there after you have done things which others have suggested.
In my case removing or setting the importHelpers
compiler option to false
resolved the issue.
{"compilerOptions": {..."importHelpers": false, // Or remove this...}}
Just updated tslib to latest version, and problem had been fixed. I had installed 1.9.3
, and updated to 1.10.0
.
As the reference states, module resolution is set to Node mode only for "modules": "commonjs"
, and is set to classic mode for "modules": "es2015"
:
There are two possible module resolution strategies: Node and Classic. You can use the --moduleResolution flag to specify the module resolution strategy. If not specified, the default is Classic for --module AMD | System | ES2015 or Node otherwise
Since classic mode is unaware of node_modules
, the compiler cannot resolve tslib
module.
moduleResolution
should be set explicitly for ES2015 modules:
..."module": "es2015","moduleResolution": "node",...
My error appeared to be sporadic but likely caused by editing a file in the "node_modules" folder.
I deleted
Ran ... "npm install"
It is now working.
NOTE: I tried running "npm install' prior to deleting the files and that did not solve the issue.
update the dependencies and devDependencies of tslib in package.json
{dependencies:{"tslib": "1.10.0",},devDependencies:{"tslib": "1.10.0",}}
In my case the error Cannot find module 'tslib'
was caused by special builder @nrwl/node:build
in my Angular repository (I'm using nrwl/nx monorepo pattern with NodeJS server as one of the applications).
It didn't include tslib
in the compilation output. Setting "externalDependencies": "none"
in the production build configuration in angular.json
solved the issue. Credit goes to @vincastl here: https://github.com/nrwl/nx/issues/2625
Posting it here as it was the first post I found trying to solve this issue, perhaps I'm not alone.
I faced this issue with jest
(+vuejs and a monorepo structure).All the app works fine, but unit tests doesn't.
So 2 things has to be done to make them work:
tsconfig.json
: "compilerOptions": {"paths": {"tslib" : ["path/to/node_modules/tslib/tslib.d.ts"]}
jest.config.js
: moduleNameMapper: {'tslib': '<rootDir>/path/to/node_modules/tslib/tslib.js'}
npm install
If you see this error the first time you open a new project or repository, you probably simply haven't installed the app's required modules yet.
In the directory of the app, run:
npm install
I was facing the same problem and it got resolved using following command!
npm install -D tslib@latest
(2023 solution)
As noted in the official tslib doc, tslib is a runtime library, therefore it must not be installed as a devDependencies
with the -D
flag. Run yarn workspace @scope/workspace add tslib
or npm i tslib -w @scope/workspace
to fix this error.
SOLUTION:
>> npm install -g npm-check-updates>> ncu -u tslib...tslib ^1.10.0 → ^2.6.0[This command will update to the compatible version]>> npm install
Just a note:In case if it doesn't work, kindly undo the tslib version and run "npm install" to revert to previous state. Because, other packages that are dependent on the older version might not be compatible. This too happened in my case.
npm i -g tslib
This solved my problem. Without -g it didn't work for me.
You have to remove from "compilerOptions": { "importHelpers": true, }
on tsconfig.json
In your project , simply run
npm i tslib
It contains all the typescript helper functions
upgrading tslib version 2.00.0
in package.json it should be"tslib": "^2.0.0"
I had a case, where the only fix was to add this manually in package.json
:
"tslib": "^2.3.1",
and run npm i
afterwards.
add these lines to tsconfig.json file and inside the compilerOptions object:
"compilerOptions": {//...rest parameters"baseUrl": "./","paths": {"tslib" : ["path/to/node_modules/tslib/tslib.d.ts"]},
Add this below line in your .csproj file inside <PropertyGroup>
:
<TypeScriptCompileBlocked>True</TypeScriptCompileBlocked>