Search code examples
javascriptangulartypescriptanimationsystemjs

Unexpected Token "<" when Importing BrowserAnimationsModule with Angular 5


I'm attempting to add the BrowserAnimationModule to my Angular 5 project and I seem to be having an incredibly stupid error occurring.

Error: (SystemJS) Unexpected token <
    SyntaxError: Unexpected token <
        at eval (<anonymous>)
        at Object.eval (http://localhost:56700/app/app.module.js:15:20)
        at eval (http://localhost:56700/app/app.module.js:71:4)
        at eval (http://localhost:56700/app/app.module.js:72:3)
    Evaluating http://localhost:56700/node_modules/@angular/platform-browser/animations.js

The project works just fine if I don't place the BroswerAnimationsModule in the imports for my NgModule.

It seems that when I load in the module its searching the wrong location for a file that doesn't exist. When following the instructions on The Angular Site I noticed its pulling from one level lower in the @angular/platform-browser/animations/animations. I'm assuming t here is something wrong with my system.config but for the life of me I just cant figure it out... Any help is appreciated. Thanks

system.config.js

(function (global) {
var map = {
    //Comment out when publishing.
    'app': '/app',
    '@angular': '/node_modules/@angular',
    'angular2-in-memory-web-api': '/node_modules/angular2-in-memory-web-api',
    'rxjs': '/node_modules/rxjs',
    '@ng-bootstrap/ng-bootstrap': '/node_modules/@ng-bootstrap/ng-bootstrap/bundles/ng-bootstrap.js'

    //Uncomment when publishing.
    //'app' : 'app',
    //'@angular': 'node_modules/@angular',
    //'angular2-in-memory-web-api': 'node_modules/angular2-in-memory-web-api',
    //'rxjs': 'node_modules/rxjs',
    //'@ng-bootstrap/ng-bootstrap': 'node_modules/@ng-bootstrap/ng-bootstrap/bundles/ng-bootstrap.js'
};
    packages = {
        'app': { main: './main.js', defaultExtension: 'js' },
        'angular2-in-memory-web-api': { main: './index.js', defaultExtension: 'js' },
        'rxjs': { defaultExtension: 'js' }
    },
    ngPackageNames = [
        'common',
        'compiler',
        'core',
        'http',
        'platform-browser',
        'platform-browser-dynamic',
        'router',
        'forms',
        'animations'
    ];

    function packUmd(pkgName) {packages['@angular/' + pkgName] = { main: '/bundles/' + pkgName + '.umd.min.js', defaultExtension: 'js' };}

ngPackageNames.forEach(packUmd);


var config = {
    map: map,
    packages: packages
};

System.config(config);})(this);

app.module.ts

//Main folder where Angular Extras are added.
//Angular Libraries
    import { NgModule, enableProdMode } from '@angular/core';
    import { FormsModule } from '@angular/forms'
    import { NgbModule,NgbAccordionModule } from '@ng-bootstrap/ng-bootstrap';
    import { BrowserModule, platformBrowser } from '@angular/platform-browser';
    import { BrowserAnimationsModule, NoopAnimationsModule } from '@angular/platform-browser/animations';
import { HttpModule } from '@angular/http';

import { RouterModule, Routes } from '@angular/router'


//Components
import { AppComponent } from './app.component';
import { INHome } from './Components/MainComponents/INHome/INHome';
import { LogoSection } from './Components/MainComponents/LogoSection/LogoSection';
import { NavBar } from './Components/MainComponents/NavBar/NavBar';
import { LeftNav } from './Components/MainComponents/LeftNav/LeftNav';
import { LineStatus } from './Components/MainComponents/LogoSection/LineStatus/LineStatus';
import { Favorites } from './Components/MainComponents/RightNav/Favorites/Favorites';
import { SearchableLinks } from './Components/MainComponents/RightNav/SearchableLinks/SearchableLinks';
import { DailySummary } from './Components/MainComponents/Departments/DailySummary/DailySummary';
import { NewsFeed } from './Components/MainComponents/Departments/DailySummary/NewsFeed/NewsFeed'
import { EditFavorites } from './Components/MainComponents/RightNav/Favorites/EditFavorites/EditFavorites'
import { Documents } from './Components/MainComponents/Departments/Documents/Documents'
import { TestComponent } from './Components/MainComponents/TestComponent/TestComponent';
import {Safety } from './Components/MainComponents/Departments/Safety/Safety'

//Classes
import { Branch, Leaf, UserDetails } from './Classes/FrontendClasses';

//Data Reading Services
import { StaticDRS } from './DataReadingServices/StaticDRS';
import { UserDetailsDRS } from './DataReadingServices/UserDetailsDRS';


//Pipes
import { LinkPipe } from '../app/Pipes/SearchableLinks'

//Utilities


enableProdMode();


//Routing Paths
const appRoutes: Routes = [
    { path: 'Home.aspx', redirectTo: 'INHome/DailySummary', pathMatch: 'full' },
    { path: '', redirectTo:'INHome/DailySummary', pathMatch:'full' },
    {
        path: 'INHome', component: INHome, children: [
            { path: 'DailySummary', component: DailySummary },
            { path: 'Documents', component: Documents },
            { path: 'Safety',component: Safety},
            { path:'', redirectTo:'DailySummary', pathMatch:'full'}
        ]
    }
    //{path:'**',component:TestComponent}
]


@NgModule({
    imports: [BrowserModule, HttpModule, NgbModule.forRoot(), FormsModule, RouterModule.forRoot(appRoutes), NgbAccordionModule,BrowserAnimationsModule],
    declarations: [AppComponent, TestComponent, INHome, LogoSection, NavBar, LeftNav, LineStatus, Favorites, SearchableLinks, DailySummary, NewsFeed, EditFavorites, LinkPipe, Documents, Safety],
    providers: [UserDetailsDRS, StaticDRS,UserDetails],
    bootstrap: [AppComponent],
})
export class AppModule { }

Let me know if you need more files.


Solution

  • For any poor soul out there that has the same issue as me:

    The error thrown was really a 404 error. Since everything was being routed through my index.html (that's the way I built my app), when it couldn't find the file it went to the index.html which starts with a <. To fix this, I added these three lines into my system.config.js in the map:

    '@angular/animations': '/node_modules/@angular/animations',
    '@angular/animations/browser': '/node_modules/@angular/animations/bundles/animations-browser.umd.js',
    '@angular/platform-browser/animations':'/node_modules/@angular/platform-browser/bundles/platform-browser-animations.umd.js'