My application was working fine, and it stopped after trying to get the documentation with swagger, i think it may be a dependency issue, but can't find it anywhere.
I keep getting the error
10:10:22 PM - Starting compilation in watch mode...
Error Cannot read property 'getSymbol' of undefined
I don't know where getSymbol is used, and the error doesn't seem to help much. Hope someone can help me fix this issue. The complete application code can be found at:
https://github.com/JSLearningCode/enderecosAlunosAPI
Any help is welcome.
EDIT:
Running in dev mode I got this output:
/home/william/Documentos/lemobs/enderecosAlunosAPI/node_modules/typescript/lib/typescript.js:95877
throw e;
^
TypeError: Cannot read property 'getSymbol' of undefined
at Object.isArray (/home/william/Documentos/lemobs/enderecosAlunosAPI/node_modules/#nestjs/swagger/dist/plugin/utils/ast-utils.js:6:25)
at getTypeReferenceAsString (/home/william/Documentos/lemobs/enderecosAlunosAPI/node_modules/#nestjs/swagger/dist/plugin/utils/plugin-utils.js:12:21)
at Object.getTypeReferenceAsString (/home/william/Documentos/lemobs/enderecosAlunosAPI/node_modules/#nestjs/swagger/dist/plugin/utils/plugin-utils.js:31:29)
at ControllerClassVisitor.createTypePropertyAssignment (/home/william/Documentos/lemobs/enderecosAlunosAPI/node_modules/#nestjs/swagger/dist/plugin/visitors/controller-class.visitor.js:51:44)
at ControllerClassVisitor.createDecoratorObjectLiteralExpr (/home/william/Documentos/lemobs/enderecosAlunosAPI/node_modules/#nestjs/swagger/dist/plugin/visitors/controller-class.visitor.js:38:18)
at ControllerClassVisitor.addDecoratorToNode (/home/william/Documentos/lemobs/enderecosAlunosAPI/node_modules/#nestjs/swagger/dist/plugin/visitors/controller-class.visitor.js:29:22)
at visitNode (/home/william/Documentos/lemobs/enderecosAlunosAPI/node_modules/#nestjs/swagger/dist/plugin/visitors/controller-class.visitor.js:16:29)
at visitNodes (/home/william/Documentos/lemobs/enderecosAlunosAPI/node_modules/typescript/lib/typescript.js:70998:48)
at Object.visitEachChild (/home/william/Documentos/lemobs/enderecosAlunosAPI/node_modules/typescript/lib/typescript.js:71266:355)
at visitNode (/home/william/Documentos/lemobs/enderecosAlunosAPI/node_modules/#nestjs/swagger/dist/plugin/visitors/controller-class.visitor.js:18:23)
error Command failed with exit code 1.
There was an issue related to the routing in the application. I had a parser inside the controller that was used for directing correct routes between a route "aluno" with first Param.
Once I had taken the route with no params and put it first at the controller, there was no need anymore for the parser, and the issue was gone. Hope this answer helps more people if they get the same problem.
Please check your method result type of controller
Change this:
#Contoller()
export class MyController {
// ...
async myMethod() {
return {}
}
}
to:
#Contoller()
export class MyController {
// ...
async myMethod():Promise<any> {
return {}
}
}
I'm very new to Angular and I'm trying to figure much of this out still. I'm writing some tests using Angular 1.5.8 which I generated from the Yeoman Generator.
Specifically, I'm trying to figure out how to manipulate $httpBackend results (I'm not sure if that's important or not)...
In my app.js file I have the following code:
.run(['$rootScope', '$location', 'breadcrumbService', function ($rootScope, $location, breadcrumbService) {
$rootScope.$on('$viewContentLoaded', function () {
jQuery('html, body').animate({scrollTop: 0}, 200);
});
$rootScope.isEditMode = false;
$rootScope.$on('$stateChangeSuccess', function () {
// ------------ this next line is failing -----------
$rootScope.isEditMode = $location.path().toLowerCase().endsWith('/edit') || $location.path().toLowerCase().endsWith('/new');
});
$rootScope.parseJson = function (value) {
return angular.fromJson(value);
};
$rootScope.bc = breadcrumbService;
$rootScope.title = "";
}])
The line about halfway down (where I added the comment) is failing. Specifically, the endsWith function is failing (toLower is fine), with this error:
PhantomJS 2.1.1 (Windows 8 0.0.0) Service: breadcrumbService should return breadcrumb label in json format FAILED
TypeError: undefined is not a constructor (evaluating '$location.path().toLowerCase().endsWith('/edit')') in app/scripts/app.js (line 44)
app/scripts/app.js:44:72
$broadcast#bower_components/angular/angular.js:18005:33
bower_components/angular-ui-router/release/angular-ui-router.js:3353:32
processQueue#bower_components/angular/angular.js:16383:30
bower_components/angular/angular.js:16399:39
$eval#bower_components/angular/angular.js:17682:28
$digest#bower_components/angular/angular.js:17495:36
$apply#bower_components/angular/angular.js:17790:31
done#bower_components/angular/angular.js:11831:53
handleResponse#bower_components/angular-mocks/angular-mocks.js:1368:17
flush#bower_components/angular-mocks/angular-mocks.js:1808:26
test/spec/services/breadcrumbservice.js:33:27
invoke#bower_components/angular/angular.js:4718:24
workFn#bower_components/angular-mocks/angular-mocks.js:3085:26
Here is my test code (some junk modified from different examples - just trying to get it to work):
'use strict';
describe('Service: breadcrumbService', function () {
// load the service's module
beforeEach(module('myModule'));
var $httpBackend, $rootScope, createController, authRequestHandler;
beforeEach(inject(function($injector) {
$httpBackend = $injector.get('$httpBackend');
console.log('Is null? '+ ($httpBackend == null));
$httpBackend.whenGET(/views\/.*/).respond(200, [{}, {}, {}]);
authRequestHandler = $httpBackend.when('GET', '/api/v1/SiteStagings')
.respond({userId: 'userX'}, {'A-Token': 'xxx'});
// Get hold of a scope (i.e. the root scope)
$rootScope = $injector.get('$rootScope');
$httpBackend.flush();
}));
// instantiate service
var breadcrumbService;
beforeEach(inject(function (_breadcrumbService_) {
breadcrumbService = _breadcrumbService_;
}));
it('svc should exist', function () {
expect(!!breadcrumbService).toBe(true);
});
it('should return breadcrumb label in json format', function () {
var result = breadcrumbService.getFromCache('site', 'SiteGroupStagings', 46, 'SiteGroupDesc');
console.log(result);
expect(!!result).toBe(true);
});
});
I don't doubt that I'm doing something wrong here, I just can't quite understand what it is. What does this error really mean and why does it not like my call to endsWith?
Thanks
undefined is not a constructor
is an error message PhantomJS displays when you tried to call a function that is not defined. It depends on the version of ECMAScript which your PhantomJS supports. So as you said it works fine in Chrome, because this browser supports the function you are using in test.
In order to fix your problem and still be able to use PhantomJS you can replace the "unknown to PhantomJS" function with some alternative function.
I was getting TypeError: undefined is not a constructor error using the includes() method. The includes() and endsWith() methods are new in ECMAScript 2015, and are not supported in Internet Explorer, and evidently not by PhantomJS.
There is a chance your end user may be using Internet Explorer. In which case, you may want to use the fully supported indexOf() method instead of includes() or endsWith()
For example, in my case, everything worked great in chrome, but my tests were failing on the line:
if (item.name.includes('contents'))
I changed to using the indexOf() method instead:
if (item.name.indexOf('contents') !== -1)
And then I was no longer getting the error
TypeError: undefined is not a constructor
I debated whether or not to post this as an answer or just an edit to my question, but I guess it's my answer (for now):
It seems the problem is related to PhantomJS. As soon as I changed the engine to Chrome in the karma.conf.js file, those tests passed.
I still don't know what that error message is supposed to mean and why it wasn't working with PhantomJS, but at least I'm now able to continue.
Here are the modifications to my karma.conf.js (in case anyone is curious):
browsers: [
//'PhantomJS',
'Chrome'
],
// Which plugins to enable
plugins: [
'karma-chrome-launcher',
//'karma-phantomjs-launcher',
'karma-jasmine'
],
Btw - I did notice that endsWith is new to ECMAScript6 (I was thinking it was older), but WebStorm shows that it's referencing a helper function in angular-ui-grid. I spent quite a while messing with the files array in the karma.conf.js file in an attempt to see if the ui-grid dependency was loading too late or something. In every test, it worked fine in Chrome but not PhantomJS. I still have no idea why.
In My Case: Cyclic Dependencies Causing:
PhantomJS 2.1.1 (Windows 8 0.0.0) ERROR TypeError: undefined is not a constructor (evaluating '(0, _actions.prefix)('SET_USER_INPUT_PHONE_NUMBER')') at undefined:12
I got the same error after I added imports in my javascript production code (ES6 syntax compiled with babel/webpack).
The changes were fine when a production build of the application was loaded in chrome but running the tests with phantomJS produced the error.
In my case the added imports created cyclic dependencies.
I'm dropping this here for future reference (I stumbled upon the same problem a few weeks ago and don't want to scratch my head again in another couple of weeks) and for others that google the same error.
I faced similar error with PhantomJS:
For me the error was the way in which I was creating a spy object for my service.
Error on line in code file new Service.getData(param1, param2)
Fix in test file: jasmine.createSpyObj('Service',['getData'])
What is was missing was adding ['getData] while creating spyObj
I'm trying to update some texts on a page that is part of $scope. But I keep getting this error:
Error: [$rootScope:inprog] [http://errors.angularjs.org/1.2.15/$rootScope/inprog?p0=%24apply][1]
at Error (native)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js:6:450
at m (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js:101:443)
at h.$apply (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js:108:301)
at h.$scope.changeLang (http://treenovum.es/xlsmedical/js/medical-app.js:80:16)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js:169:382
at https://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js:186:390
at h.$eval (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js:108:40)
at h.$apply (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js:108:318)
at HTMLAnchorElement.<anonymous> (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js:186:372)
Obviously I'm doing something wrong. :)
Any ideas of how I can fix this? I want the page to update to the new variables in the scope.
This is the code I'm using for updating:
medicalApp.controller('MainCtrl', function($scope, $cookies, getTranslation) {
getTranslation.get(function(data){
$scope.translation = data;
});
$scope.changeLang = function (lang) {
console.log(lang);
$cookies.lang = lang;
$scope.$apply(function(){
getTranslation.get(function(data){
$scope.translation = data;
console.log(JSON.stringify($scope.translation));
});
});
};
});
the html:
<body ng-controller="MainCtrl">
...
<div class="header-lang col-xs-4">
<p>
DE |
FR</p>
<div>{{ translation.text }}</div> <---- Example variable I want updated.
...
I'm also using ngRoute with separate controllers for each page I load, if that has anything todo with it?
If your template don't change after changing models and you need using $scope.$apply, You can use $scope.$applyAsync instead of this.
https://github.com/angular-ui/ui-codemirror/issues/73
You are using $scope.$apply(...) inside the function changeLang so you are getting the common 'already in a digest' error. You don't need to put the call to getTranslation inside a $scope.$apply(...) block because ng-click already has you taken care of. Yank that out and it should just work. Also, I'd recommend running with a non-minified version of angular for dev so you can see better errors in your console.
$evalAsync works great:
$scope.$evalAsync(function() {
// Code here
});
Or simply:
$scope.$evalAsync();
See: https://docs.angularjs.org/api/ng/type/$rootScope.Scope#$evalAsync
I am trying to get testing working in Ember.js with the Ember.testing = true flag set to disable the automatic run loop etc
I have this code
Ember.testing = true;
Ember.run(function() {
App = Ember.Application.create();
});
App.Router.map(function() {
this.route("home", { path: "/" });
});
Ember.run(function() {
App.initialize();
});
And i get thuis error already
Uncaught Error: assertion failed: You have turned on testing mode, which disabled the run-loop's autorun. You will need to wrap any code with asynchronous side-effects in an Ember.run
I know you need to run async code within a Ember.run which i have as per any examples i can find!!
Can anyone show me what i am doing wrong or even get the jsin example to not show this error ?
See jsbin here http://jsbin.com/uxalap/14/edit
UPDATED:
I am using Konacha to run my tests and when i use the latest RC1 i get an error when wrapping the Ember.Application.create() and App.initialize() in Em.run. When i remove these i get no errors. Is this correct now in latest master ?
Thanks
Rick
Ember.testing was changed since RC1, if you want to use it you should use master
Here's an updated working JSBin
I'm learning backbone.js and already have a problem.
I'm loading my scripts with LABjs like this:
$LAB.setOptions({BasePath : path})
.script('libs/underscore.js?v=1.3.3')
.script('libs/backbone.js?v=0.9.2')
.script('libs/jquery.js?v=1.7')
.script('libs/bootstrap.min.js?v=2.0.2').wait()
.script('test.js');
In my test.js I have this (from backbonetutorials.com):
(function($){
SearchView = Backbone.View.extend({
initialize: function(){
alert("Alerts suck.");
}
});
var search_view = new SearchView;
})(jQuery);
As you see this should give me an alert with text "Alerst suck.".
Instead it throws an error on my firebug console - i is not a function (34 line of backbone.js).
If I try to initialize view like this var search_view = new SearchView({el: $('#some_dom_element')}); it gives me another error - invalid 'instanceof' operand i (34 line of backbone.js file).
jQuery object $ is defined.
I can initialize Backbone.js models without any problems. Just view throws those errors. What I am missing?
It seems that order in which scripts are loaded matters. I've loaded jQuery first now and it started to work. I've also tested it with non minified version of backbone.js and the error was more verbose $ is not a function. So again - loading jQuery before backbone.js fixed it.
EDIT: When loading jQuery after backbone.js when I do console.log($) right before view initialization it shows tha $ is a function. Why backbone.js fails to work then? Can someone explain this?