Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TS2354 This syntax requires an imported helper but module 'tslib' cannot be found. #12

Closed
bluetech opened this issue Apr 18, 2017 · 19 comments
Labels
kind: support Asking for support with something or a specific use case scope: dependencies Issues or PRs about updating a dependency scope: docs Documentation could be improved. Or changes that only affect docs solution: tsc behavior This is tsc's behavior as well, so this is not a bug with this plugin

Comments

@bluetech
Copy link
Contributor

bluetech commented Apr 18, 2017

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.

@ezolenko
Copy link
Owner

ezolenko commented Apr 18, 2017

This is definitely supposed to work transparently (and works for me in my own projects). I'll try your exact setup, thanks.

@ezolenko
Copy link
Owner

ezolenko commented Apr 19, 2017

Looks like you need "moduleResolution": "node" in tsconfig, otherwise typescript can't find tslib in node_modules.

Not sure if that could pose problems on non-node setups, but I haven't heard anything to that effect yet.

@bluetech
Copy link
Contributor Author

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!

@hueitan
Copy link

hueitan commented Sep 19, 2019

Not sure anyone else facing the same problem as mine.

I was having this problem rollup/rollup-plugin-typescript#109, therefore I switch to this repo, but then I'm getting this tslib error.

as the tsconfig is already "moduleResolution": "node"

@ezolenko
Copy link
Owner

If you post your tsconfig, rollup config and package.json, somebody might spot something amiss.

@giniedp
Copy link

giniedp commented Sep 28, 2019

@hueitan i faced the same issue while already having "moduleResolution": "node". Fixed it by adding "tslib": "^1.10.0" to my devDependencies.

@hueitan
Copy link

hueitan commented Oct 1, 2019

adding tslib as the dependencies work to me as well. although not the pretty solution

@ezolenko
Copy link
Owner

ezolenko commented Oct 1, 2019

tslib is already a dependency of rollup-plugin-typescript2, how does it end up missing on your system?

Do you use npm install or something else?

@giniedp
Copy link

giniedp commented Oct 1, 2019

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.json

I can reproduce it in the following repo:

https://github.com/giniedp/tweak-ui

git clone git@github.com:giniedp/tweak-ui.git
cd tweak-ui
git checkout v0.1.0

now edit the package.json and remove tslib. Then do

yarn install
yarn run build

you should run into

This syntax requires an imported helper named '__spreadArrays', but module 'tslib' has no exported member '__spreadArrays'

now delete the yarn.lock and then

yarn install
yarn run build

runs fine.

victorhqc added a commit to victorhqc/touchbar-electron-renderer that referenced this issue Oct 4, 2019
@imnickvaughn
Copy link

imnickvaughn commented Oct 4, 2019

This was fixed with this

@hueitan i faced the same issue while already having "moduleResolution": "node". Fixed it by adding "tslib": "^1.10.0" to my devDependencies.

Fixed! Mine was in regular dependencies.

@vishnu-85
Copy link

vishnu-85 commented Jan 19, 2020

Fixed it by adding "tslib": "^1.10.0" to my dependencies.

@Seanmclem
Copy link

Seanmclem commented Apr 28, 2020

npm i tslib -D

worked for me too

@mesqueeb
Copy link
Contributor

mesqueeb commented May 17, 2020

Like @ezolenko says: While npm i tslib -D works, this should not be used as the solution, because:

tslib is already a dependency of rollup-plugin-typescript2, how does it end up missing on your system?

Do you use npm install or something else?

What worked in my case and is the better solution is to delete package-lock and node_modules and reinstall.

rm -rf ./node_modules
rm -rf ./package-lock.json
npm i

@Yangsou
Copy link

Yangsou commented May 21, 2020

@hueitan i faced the same issue while already having "moduleResolution": "node". Fixed it by adding "tslib": "^1.10.0" to my devDependencies.

Thank you, It's so helpful

@caroso1222
Copy link

caroso1222 commented Jul 7, 2020

None of the proposed solutions worked for me. Upgrading rollup-plugin-typescript2 did the trick.

npm i rollup-plugin-typescript2@0.27.1

It turns out rollup was using tslib@1.9.3 even when I had ^1.10.0 in devDependencies. I realized rollup-plugin-typescript2 was overriding the tslib version. I was using v0.20.1; upgraded to v0.27.1.

@zimejin
Copy link

zimejin commented Jul 19, 2020

Weird behavior, But restarting VS code worked for me. I didn't have the issue previously, it just came up after doing an package install.

@irodger
Copy link

irodger commented Nov 30, 2020

Fixed it by adding "tslib": "^1.10.0" to my dependencies.

Thanks. Just added to peerDependencies and it works well for me, do not need to install

@yehonadav
Copy link

yehonadav commented Apr 1, 2021

I had this error:

semantic error TS2343: This syntax requires an imported helper named '__spreadArray' which does not exist in 'tslib'. Consider upgrading your version of 'tslib'.

Fixed it by adding "tslib": "^2.1.0" to my dependencies.

@aman2talk
Copy link

aman2talk commented Apr 16, 2021

You can simply upgrade your tslib version. I did mine from tslib@2.0.0 to tslib@^2.2.0 which is the latest one by the time and it fixed my "__spreadArray" issue.

greatSumini added a commit to greatSumini/react-analytics-provider that referenced this issue Aug 28, 2021
greatSumini added a commit to EveryAnalytics/react-analytics-provider that referenced this issue Aug 29, 2021
* chore: add .yarnrc.yml

* chore: add yarn-berry.cjs

* chore: install packages with yarn berry

* chore: ignore yarn related files

* chore: remove package-lock.json

* chore: enable Plug'n'Play

* chore: enable vscode integrations

- ref: https://yarnpkg.com/getting-started/editor-sdks

* chore: enable Yarn's Typescript plugin

- helps manage `@types/*` dependencies automatically
- ref: https://github.com/yarnpkg/berry/tree/master/packages/plugin-typescript

* chore: upgrade rollup-plugin-typescript2(v0.30.0), add tslib

- to fix module 'tslib' cannot be found error
- ref: ezolenko/rollup-plugin-typescript2#12

* chore: install yarn pnpify

* test: fix "cannot find global" ts error

* chore: remove .yarn/install-state.gz

* ci: apply yarn to CI workflow scripts

* docs: update CONTRIBUTING to use yarn berry

* ci: update CI workflow to not use actions-yarn

- 퍼포먼스가 30초 vs 2초로 너무 파멸적으로 차이나기 때문에 배제했습니다.

* docs: fix typo in CONTRIBUTING

* chore: add yarn files, dir to .npmignore

* chore: install amplitude-js with yarn

* test: remove unnecessary global
@agilgur5 agilgur5 added the scope: dependencies Issues or PRs about updating a dependency label May 2, 2022
@agilgur5 agilgur5 added kind: support Asking for support with something or a specific use case scope: docs Documentation could be improved. Or changes that only affect docs labels May 21, 2022
@agilgur5 agilgur5 changed the title This syntax requires an imported helper but module 'tslib' cannot be found. TS2354 This syntax requires an imported helper but module 'tslib' cannot be found. May 22, 2022
@agilgur5 agilgur5 added solution: tsc behavior This is tsc's behavior as well, so this is not a bug with this plugin and removed solution: tsc behavior This is tsc's behavior as well, so this is not a bug with this plugin labels Jun 21, 2022
apperside added a commit to apperside/react-query-typed-api that referenced this issue Jan 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: support Asking for support with something or a specific use case scope: dependencies Issues or PRs about updating a dependency scope: docs Documentation could be improved. Or changes that only affect docs solution: tsc behavior This is tsc's behavior as well, so this is not a bug with this plugin
Projects
None yet
Development

No branches or pull requests