Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invalid 'reference' directive syntax error when referencing angular 1.5

I have upgraded to Typescript 2.0.3 yesterday and updated the reference path to

/// <reference types="angular" />

after installing the typings for Angular 1.5x using the following command

npm install -s @types/angular

I get the error when I build the project and the error doesn't go away.

Invalid 'reference' directive syntax

How does one fix this?

/// <reference types="angular" />
/// <reference types="d3" />

(function () {
    'use strict';

    var app = angular.module('charts', []);

    app.controller('mainCtrl', function mainCtrl($scope, appService) {

        var vm = this;

        vm.data1 = [1, 2, 3, 4];
        vm.data2 = [4, 5, 7, 11];
        vm.update = function (d, i) {
            vm.data1 = appService.GetRandomData();
            console.log('new data1', vm.data1);
        };

        vm.update2 = function (d, i) {
            vm.data2 = appService.GetRandomData();
            console.log('new data2', vm.data2);
        };
    });

    app.directive('barChart', function ($timeout) {
        var chart = d3.custom.barChart();
        return {
            restrict: 'E',
            replace: true,
            scope: true,
            bindToController: {
                data: '=',
            },
            controller: 'mainCtrl',
            controllerAs: 'ctrl',
            link: function (scope, element, attrs, ctrl) {
                var chartEl = d3.select(element[0]);

                chartEl.datum(ctrl.data).call(chart)
            }
        }
    });

    app.directive('chartForm', function () {
        return {
            restrict: 'E',
            replace: true,
            controller: 'mainCtrl',
            templateUrl: 'chartform.html'
        }
    });

    app.service('appService', function () {
        this.GetRandomData = function () {
            var rdata;

            rdata = d3.range(~~(Math.random() * 50) + 1).map(function (d, i) {
                return ~~(Math.random() * 100);
            });

            return rdata;
        }
    });

} ());
like image 668
Animesh Avatar asked Dec 18 '22 13:12

Animesh


2 Answers

I was getting this error in the build server, VSTS.

Upgrading the type script version resolved my issue.

In package,json: changed from

"typescript": "2.8.3"

to

 "typescript": "3.5.1"
like image 59
Malu MN Avatar answered May 19 '23 18:05

Malu MN


I have updated the typescript path in workspace settings file .vscode/settings.json to point to the latest typescript version. This will make VS Code to use the latest version typescript.

{
    "typescript.tsdk": "C:\\Users\\UserName\\AppData\\Roaming\\npm\\node_modules\\typescript\\lib"
}

I didn't assume this to be the problem because when I run tsc -v in the integrated terminal, I got 2.0.3.

Now I am onto fixing the compiler errors.

Helpful links:

  • Can I use a relative path to configure typescript sdk?
  • "Invalid 'reference' directive syntax" Typescript2 @types references
like image 21
Animesh Avatar answered May 19 '23 19:05

Animesh