microsoft / tslib

Runtime library for TypeScript helpers.
BSD Zero Clause License
1.26k stars 128 forks source link

module 'tslib' cannot be found #12

Closed GaryB432 closed 7 years ago

GaryB432 commented 7 years ago

Hi guys. I'm getting this error when I run `node_modules/.bin/tsc' in the following folder.

error TS2354: This syntax requires an imported helper but module 'tslib' cannot be found.

The offending line (rxjs/Subscriber.d.ts(13,36) does indeed include an innocent looking extend keyword. Can you tell me what I'm doing wrong?

$ node_modules/.bin/tsc
node_modules/rxjs/Subscriber.d.ts(13,36): error TS2354: This syntax requires an imported helper but module 'tslib' cannot be found.

src/main.ts

import { Observable } from "rxjs";

Observable.timer(3000, 5000)
  .timeInterval()
  .subscribe((interval) => console.log(interval));

tsconfig.json

{
  "compilerOptions": {
    "module": "commonjs",
    "importHelpers": true,
    "target": "es5",
    "noEmitHelpers": true
  }
}

package.json

{
  "name": "stuff",
  "version": "1.0.0",
  "scripts": {
    "build": "webpack"
  },
  "devDependencies": {
    "@types/core-js": "^0.9.35",
    "ts-loader": "^1.3.2",
    "typescript": "^2.1.4",
    "webpack": "^2.1.0-beta.25"
  },
  "dependencies": {
    "rxjs": "^5.0.1",
    "tslib": "^1.2.0"
  }
}

rxjs/Subscriber.d.ts(13)

export declare class Subscriber<T> extends Subscription implements Observer<T> {

I posted my question to stackoverflow but can't get any interest

mhegazy commented 7 years ago

Looks like a duplicate of https://github.com/Microsoft/TypeScript/issues/12724

can you give typescript@2.2.0-dev.20161215 a try?

GaryB432 commented 7 years ago

yeah that seems to work. thanks! I guess I'll wait for 2.2 to go to latest before leaving ts-helpers behind

mhegazy commented 7 years ago

We should be publishing 2.1.5 with he fix soon.

garthk commented 7 years ago

@mhegazy any clarity you can offer on "soon"?

mhegazy commented 7 years ago

We are targeting next week.

Strato commented 7 years ago

Hello,

I've installed TypeScript 2.1.5 Tools for Visual Studio as well as the npm package globally AND in my project, and I'm still getting red squiggly lines under code like this:

extends React.Component<{}, {}>

Tooltip error being this syntax requires an imported helper but module 'tslib' cannot be found.

Note that it doesn't prevent the project from being transpiled.

TSLib 1.5.0 is in my package.json dependencies section, and it's in _nodemodules. tsconfig has importHelpers = true.

Since it's Visual Studio related I tried to add this line (not documented but makes sense) in my .csproj:

<TypeScriptImportHelpers>True</TypeScriptImportHelpers>

I'm not supposed to import it explicitly, do I? Or maybe point to a definition file?

mhegazy commented 7 years ago

@Strato, this looks like a bug do you mind filing a new issue under https://github.com/Microsoft/TypeScript/issues

Strato commented 7 years ago

Done.

rahulswimmer commented 6 years ago

Following is my package.json

 {
   "name": "digital-labels",
   "version": "0.0.0",
   "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "compodoc": "compodoc -p src/tsconfig.app.json"
 },
  "private": true,
  "dependencies": {
  "@angular/animations": "^6.0.7",
  "@angular/cdk": "^6.3.2",
  "@angular/common": "^6.0.3",
  "@angular/compiler": "^6.0.3",
  "@angular/core": "^6.0.3",
  "@angular/forms": "^6.0.3",
  "@angular/http": "^6.0.3",
  "@angular/material": "^6.3.2",
  "@angular/platform-browser": "^6.0.3",
  "@angular/platform-browser-dynamic": "^6.0.3",
  "@angular/pwa": "^0.6.8",
  "@angular/router": "^6.0.3",
  "@angular/service-worker": "^6.0.3",
  "@ng-idle/core": "^6.0.0-beta.3",
  "angularx-social-login": "^1.2.0",
  "core-js": "^2.5.4",
  "hammerjs": "^2.0.8",
  "hide-virtual-keyboard": "^1.0.1",
  "ng2-avatar": "^2.3.1",
  "ng2-search-filter": "^0.4.7",
  "rxjs": "^6.0.0",
  "tslib": "^1.9.3",
  "zone.js": "^0.8.26"
  },
  "devDependencies": {
  "@angular-devkit/build-angular": "~0.6.8",
  "@angular/cli": "~6.0.8",
  "@angular/compiler-cli": "^6.0.3",
  "@angular/language-service": "^6.0.3",
  "@compodoc/compodoc": "^1.1.3",
  "@types/jasmine": "~2.8.6",
  "@types/jasminewd2": "~2.0.3",
  "@types/node": "~8.9.4",
  "codelyzer": "~4.2.1",
  "jasmine-core": "~2.99.1",
  "jasmine-spec-reporter": "~4.2.1",
  "karma": "~1.7.1",
  "karma-chrome-launcher": "~2.2.0",
  "karma-coverage-istanbul-reporter": "~2.0.0",
  "karma-jasmine": "~1.1.1",
  "karma-jasmine-html-reporter": "^0.2.2",
  "protractor": "~5.3.0",
  "ts-node": "~5.0.1",
  "tslint": "~5.9.1",
  "typescript": "~2.7.2"
  },
  "description": "This project was generated with [Angular CLI](https://github.com/angular/angular-cli) 
   version 6.0.8.",
 "main": "index.js",
 "repository": {
  "type": "git",
     "url": "git+https://rahul1406@bitbucket.org/morrisonsplc/esels-digital-labels-pwa.git"
  },
  "author": "",
  "license": "ISC",
  "homepage": "https://bitbucket.org/morrisonsplc/esels-digital-labels-pwa#readme"
 }

Once i run 'ng test', i receive the following errors:

1) No captured browser, open http://localhost:9876/ 2) Uncaught Error: Cannot find module "tslib".

I deleted node_modules and ran 'npm install'. But this solution didn't work. What should i do? I can't run karma test runner and hence a blocker in my test driven development cycle. Please suggest me a solution!

tony2tones commented 5 years ago

try npm install --save tslib, thats what helped me out.