brtnshrdr / angular2-hotkeys

Keyboard shortcuts for Angular 2 apps
MIT License
203 stars 95 forks source link

error TS1086: An accessor cannot be declared in an ambient context. node_modules/angular2-hotkeys/lib/hotkeys.service.d.ts(9,16): error TS2304: Cannot find name 'MousetrapInstance' #137

Closed shah20 closed 4 years ago

shah20 commented 4 years ago

Getting this error. It was working fine and there is not change in code but tried taking build today and it started giving this error. No package dependencies changed also. Also tried solution given in issue #3 installing typings but it is shown deprecated but still it didnt worked. I am using 2.1.5 version of angular hotkeys.

ERROR in node_modules/angular2-hotkeys/lib/hotkey.model.d.ts(24,9): error TS1086: An accessor cannot be declared in an ambient context. node_modules/angular2-hotkeys/lib/hotkeys.service.d.ts(9,16): error TS2304: Cannot find name 'MousetrapInstance'

following are dev Dependencies "devDependencies": { "@angular-devkit/build-angular": "0.13.0", "@angular/cli": "7.3.1", "@angular/compiler-cli": "^7.2.5", "@angular/language-service": "7.2.0", "@types/jasmine": "2.8.8", "@types/jasminewd2": "2.0.3", "@types/node": "8.9.4", "codelyzer": "4.5.0", "jasmine-core": "2.99.1", "jasmine-spec-reporter": "4.2.1", "karma": "^4.0.0", "karma-chrome-launcher": "2.2.0", "karma-coverage-istanbul-reporter": "2.0.1", "karma-jasmine": "1.1.2", "karma-jasmine-html-reporter": "0.2.2", "protractor": "5.4.0", "sonar-scanner": "^3.1.0", "ts-node": "7.0.0", "tslint": "^5.11.0", "tslint-sonarts": "^1.9.0", "typescript": "3.2.2" }

nodulusteam commented 4 years ago

I've resolved this issue temporarily by using yarn resolutions.

"resolutions": {   
    "@types/mousetrap": "1.6.3"
},
shah20 commented 4 years ago

@nodulusteam should I add this in package.json at the same level as devDependencies?

nodulusteam commented 4 years ago

As it's sibling yes.

shah20 commented 4 years ago

@nodulusteam I tried, it is working on my local but same thing on jenkins is giving error "Cannot find name 'MousetrapInstance". I also commited package-lock from my local and tried and also tried adding "preinstall": "npx npm-force-resolutions"

shah20 commented 4 years ago

the error is at line no. 9 of below pic from node_modules of hotkeys hotkeys error

there is no import statement coming at top for mouseTrapinstance.

while in actual code it is

import { Inject, Injectable } from '@angular/core';
import { Hotkey } from './hotkey.model';
import { Subject } from 'rxjs';
import { HotkeyOptions, IHotkeyOptions } from './hotkey.options';
import 'mousetrap';

is this what creating problem?

nodulusteam commented 4 years ago

Yes, my suggestion was for yarn, so that's probably the difference. The latest version of mousetrap types had a breaking change in the patch, causing your build to fail. I'm not the owner of this repo, so like you, I'm waiting for the fix pr to be merged.

shah20 commented 4 years ago

@nodulusteam sure after merge it would work fine. And thank you for all the help :)

shah20 commented 4 years ago

135