rollup-plugin-typescript2: `TS2354 This syntax requires an imported helper but module 'tslib' cannot be found.`
I see that the code has some references to tslib
and importHelpers
so I assume this should work transparently. If not, I’ll be happy to know what is missing.
Here is how to reproduce:
Installed packages:
$ npm ls --depth=0
├── resolve@1.3.2
├── rollup@0.41.6
├── rollup-plugin-typescript2@0.4.0
├── tslib@1.6.0
└── typescript@2.2.2
tsconfig.json
:
{
"compilerOptions": {
"target": "es5"
}
}
rollup.config.js
:
import typescript from 'rollup-plugin-typescript2';
export default {
entry: './main.ts',
plugins: [
typescript()
]
}
main.ts
:
import {Foo} from './module';
console.log("HERE" + Foo);
And module.ts
:
export class Foo {}
export class Bar extends Foo {}
When running rollup as follows:
./node_modules/.bin/rollup -c rollup.config.js
I get this error:
🚨 rpt2: module.ts (3,18): semantic error TS2354 This syntax requires an imported helper but module 'tslib' cannot be found.
module.ts
I think this is because the extends
syntax requires an __extends
helper from tslib
, but typescript can’t find tslib
.
Expected result is that the required helpers become part of the bundle.
Thanks.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 5
- Comments: 19 (6 by maintainers)
Commits related to this issue
- fix: weird tslib error on object spread operator https://github.com/ezolenko/rollup-plugin-typescript2/issues/12 — committed to jasonkuhrt/forto by jasonkuhrt 6 years ago
- build: fix package-lock https://github.com/ezolenko/rollup-plugin-typescript2/issues/12#issuecomment-537133693 — committed to victorhqc/touchbar-electron-renderer by victorhqc 5 years ago
- chore: upgrade rollup-plugin-typescript2(v0.30.0), add tslib - to fix module 'tslib' cannot be found error - ref: https://github.com/ezolenko/rollup-plugin-typescript2/issues/12 — committed to greatSumini/react-analytics-provider by greatSumini 3 years ago
- chore: Yarn berry 설정 (#163) * chore: add .yarnrc.yml * chore: add yarn-berry.cjs * chore: install packages with yarn berry * chore: ignore yarn related files * chore: remove package-lock.... — committed to EveryAnalytics/react-analytics-provider by greatSumini 3 years ago
- added tslib dev lib because of this issue https://github.com/ezolenko/rollup-plugin-typescript2/issues/12\#issuecomment-536173372 — committed to apperside/react-query-typed-api by apperside 2 years ago
Looks like you need
"moduleResolution": "node"
in tsconfig, otherwise typescript can’t findtslib
innode_modules
.Not sure if that could pose problems on non-node setups, but I haven’t heard anything to that effect yet.
@hueitan i faced the same issue while already having
"moduleResolution": "node"
. Fixed it by adding"tslib": "^1.10.0"
to my devDependencies.This was fixed with this
Fixed! Mine was in regular
dependencies
.Not sure anyone else facing the same problem as mine.
I was having this problem https://github.com/rollup/rollup-plugin-typescript/issues/109, therefore I switch to this repo, but then I’m getting this
tslib
error.as the tsconfig is already
"moduleResolution": "node"
in my case i am using yarn. Deleting the yarn.lock and reinstalling fresh, i do not need an explicit mention of
tslib
in the package.jsonI can reproduce it in the following repo:
https://github.com/giniedp/tweak-ui
now edit the
package.json
and removetslib
. Then doyou should run into
now delete the
yarn.lock
and thenruns fine.
Fixed it by adding
"tslib": "^1.10.0"
to mydependencies
.worked for me too
adding
tslib
as the dependencies work to me as well. although not the pretty solutionNone of the proposed solutions worked for me. Upgrading
rollup-plugin-typescript2
did the trick.It turns out rollup was using
tslib@1.9.3
even when I had^1.10.0
indevDependencies
. I realizedrollup-plugin-typescript2
was overriding the tslib version. I was usingv0.20.1
; upgraded tov0.27.1
.Like @ezolenko says: While
npm i tslib -D
works, this should not be used as the solution, because:What worked in my case and is the better solution is to delete package-lock and node_modules and reinstall.
You can simply upgrade your
tslib
version. I did mine fromtslib@2.0.0
totslib@^2.2.0
which is the latest one by the time and it fixed my"__spreadArray"
issue.tslib
is already a dependency ofrollup-plugin-typescript2
, how does it end up missing on your system?Do you use
npm install
or something else?If you post your tsconfig, rollup config and package.json, somebody might spot something amiss.
Indeed, with
"moduleResolution": "node"
, it works as expected. Reading https://www.typescriptlang.org/docs/handbook/module-resolution.html, I think"node"
is a better fit for me, so I’ll just use it. May I suggest mentioning/recommending it in the README?I see that you opened #14 for the
"classic"
case, so I’ll close this. Thanks!