gund / ng-http-interceptor

Http Interceptor library for Angular
MIT License
104 stars 16 forks source link

Uncaught ReferenceError: __decorate is not defined #127

Closed Arvraepe closed 7 years ago

Arvraepe commented 7 years ago

Getting this error when trying to include the module and trying to add interceptors

Arvraepe commented 7 years ago

Full trace:

component-interaction.service.ts:3Uncaught ReferenceError: decorate is not defined at component-interaction.service.ts:3 at Object.201 (component-interaction.service.ts:12) at webpack_require (bootstrap 750a398…:52) at Object.757 (app.module.ts:57) at webpack_require (bootstrap 750a398…:52) at Object.756 (main.ts:13) at webpack_require (bootstrap 750a398…:52) at Object.594 (src async:7) at webpack_require (bootstrap 750a398…:52) at Object.1230 (main.bundle.js:7) at webpack_require__ (bootstrap 750a398…:52) at webpackJsonpCallback (bootstrap 750a398…:23) at main.bundle.js:1

Arvraepe commented 7 years ago

First I had a extends is not defined... I've included ts-helpers and now I'm getting decorate is not defined.

gund commented 7 years ago

That's strange, ts-helpers should do the job... Can you post your ts-helpers version you are using? And also where are you including it in your app?

Thanjs

Arvraepe commented 7 years ago

I'm using ts-helpers version 1.1.2 and I'm including it in de main.ts file... couldn't really figure out where else to put it. Just put "import 'ts-helpers'" the extends error was gone, but decorate appeared

gund commented 7 years ago

Weird... Are you sure it is happening because of this library? Can you maybe create a plunkr so I can have a look?

Thanks

Arvraepe commented 7 years ago

It's gonna be pretty hard to make a plunkr, but to be honest I guess this isn't because of the framework. I'm also fairly new to angular2 and I f*ck up alot of these things at the moment...I've been looking into the issue and the chance that your framework is doing something wrong is very very small in my opinion. Maybe mark this as won't fix, I'll try to figure out what's wrong, if I find a solution I'll post it here for people having the same issue later.

gund commented 7 years ago

Okay, thanks.

Btw just by looking at the trace you posted above I cannot see that it's failing somewhere in files of this library but at your application file component-interaction.service.ts line 3. So just double check that file maybe there will be some hint =)

Arvraepe commented 7 years ago

Thanks! Hope I can find the issue before I get too annoyed to abandon all hope.

Necroskillz commented 7 years ago

Regarding the original error: is there any way to use tslib instead if ts-helpers (since I use it for other stuff)?

gund commented 7 years ago

Yes you can use tslib for sure (guy here confirmed #126)

Necroskillz commented 7 years ago

yeah, i've seen that, but I have no idea how he did it :P. afaik it doesn't work with webpack (because the library would have to be compiled with importHelpers flag)

gund commented 7 years ago

Actually library should be only compiled with flag "noEmitHelpers": true to exclude that code. And than when you compiling you should set that flags in your tsconfig.json:

"noEmitHelpers": true,
"importHelpers": true,

And do not forget to install tslib with package.json

Necroskillz commented 7 years ago

I have it set up like that, and it works for my library that is compiled with importHelpers: true. But webpack can't see that it should use tslib for your library (because it just uses the function, and doesn't import it).

e.g:

from transpiled code from my library:

import * as tslib_1 from "tslib";

var Class = (function (_super) {
    tslib_1.__extends(Class, _super);
}(BaseClass));

webpack generates something like:

/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_tslib__ = __webpack_require__(16);

var Class= (function (_super) {
    __WEBPACK_IMPORTED_MODULE_0_tslib__["c" /* __extends */](Class, _super);
}(BaseClass));
gund commented 7 years ago

I already did somewhere working configuration with tslib but cannot find it for now. Will check and post here once found =)

gund commented 7 years ago

Okay after a little bit of researching I found that it is really required for library to be compiled with option importHelpers: true as well =)

However this option is available only since ts 2.1+ so it is not possible currently to do for this version (v2). But I have beta branch (and npm channel) where I upgraded TS and angular together so there I can add this compilation option (actually I already added it there (: ).

Really wondering now how that guy here (#126) made it work with v2 =)

gund commented 7 years ago

/cc @rachelxi Can you please tell us you were able to utilize tslib with this lib? Thanks

rachelxi commented 7 years ago

@gund I installed tslib and just follow the instructions to do the tsconfig.json file: https://github.com/Microsoft/tslib My tsconfig.json file goes as:

{ "compileOnSave": true, "compilerOptions": { "target": "es5", "module": "commonjs", "moduleResolution": "node", "sourceMap": true, "emitDecoratorMetadata": true, "experimentalDecorators": true, "lib": [ "es2015", "dom" ], "noImplicitAny": true, "suppressImplicitAnyIndexErrors": true, "importHelpers": true, "noEmitHelpers": true, "paths": { "tslib": [ "node_modules/tslib/tslib.d.ts" ] }, "baseUrl": "./" } }

And I included tslib path in SystemJS to load the module. And it does compile well with typescript 2.1.5.

rachelxi commented 7 years ago

@gund And I don't know if it is proper to ask under this thread, but is it possible to catch all requests for 401 unauthorized response, then retry the requests on authorization success (e.g. refresh token success and get valid new access token back) ?

gund commented 7 years ago

@rachelxi Thanks for posting your config hope guys can try and it will help them.

Regarding your second question I believe that should be possible - it's only matter of how you organize your work with Observables. If you want you can create new issue and we can try to find a solution there =)

gund commented 7 years ago

Well I tried in a new project to use it with tslib and can confirm that it is not going to work with version 2 (because it was compiled with ts 2.0.x where tslib was not supported).

But beta version works fine with tslib so if you need one - use beta (and keep in mind that beta version uses angular 4-beta).