To solve the error "This syntax requires an imported helper but module 'tslib' cannot be found", install tslib by running npm install -D tslib@latest and make sure your IDE is using the correct (workspace) TypeScript version. Copied!
The tslib is a runtime library for Typescript. The version of this library is bound to the version of the TypeScript compiler used to compile a library. Peer dependencies do not accurately represent this relationship between the runtime and the compiler.
so, essentially, we can see that all the devDependencies are being removed(and note tslib ) was a dev dependency.
Noob mistake (which I just made). Try:
npm install tslib
or
npm i
Personally before signing off on Friday I did a git clean -fxd
, but no npm i
so all the npm packages were missing. Doh!
The problem for me was that the editor was using a different TypeScript version than the project.
To fix that:
Or click on the version number at the bottom bar if it shows in there:
Add below lines to tsconfig.json
"compilerOptions": {
//...rest parameters
"baseUrl": "./",
"paths": {
"tslib" : ["path/to/node_modules/tslib/tslib.d.ts"]
},
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",
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With