When attempting to import css-animator in Angular2/Typescript, a 404 error is displayed, indicating that the

Recently, I delved into the world of Angular2 and decided to experiment with some animations using css-animator

package.json

"dependencies": {
    "@angular/common": "2.0.0-rc.3",
    "@angular/compiler": "2.0.0-rc.3",
    "@angular/core": "2.0.0-rc.3",
    "@angular/forms": "0.1.1",
    "@angular/http": "2.0.0-rc.3",
    "@angular/platform-browser": "2.0.0-rc.3",
    "@angular/platform-browser-dynamic": "2.0.0-rc.3",
    "@angular/router": "3.0.0-alpha.7",
    "@angular/router-deprecated": "2.0.0-rc.2",
    "@angular/upgrade": "2.0.0-rc.3",
    "angular2-in-memory-web-api": "0.0.12",
    "bootstrap": "^3.3.6",
    "chokidar": "^1.6.0",
    "core-js": "^2.4.0",
    "css-animator": "^1.2.4",
    "http-proxy": "^1.14.0",
    "reflect-metadata": "^0.1.3",
    "rxjs": "5.0.0-beta.6",
    "systemjs": "0.19.27",
    "zone.js": "^0.6.12"
 }

index.html

<html>
  <head>
   <title>Angular 2 QuickStart</title>
   <meta charset="UTF-8">
   <meta name="viewport" content="width=device-width, initial-scale=1">
   <link rel="stylesheet" href="app/css/bootstrap.css">
   <link rel="stylesheet" href="app/css/style.css">
   <!-- 1. Load libraries -->
 <!-- Polyfill(s) for older browsers -->
    <script src="node_modules/core-js/client/shim.min.js"></script>
    <script src="node_modules/zone.js/dist/zone.js"></script>
    <script src="node_modules/reflect-metadata/Reflect.js"></script>
   <script src="node_modules/systemjs/dist/system.src.js"></script>
   <script src="node_modules/css-animator/builder/animation_builder.js">      </script>
   <!-- 2. Configure SystemJS -->
   <script src="systemjs.config.js"></script>
   <script>
     System.import('app').catch(function(err){ console.error(err); });
   </script>
         </head>
     <!-- 3. Display the application -->
        <body class="bg-image">
          <my-app>Loading...</my-app>
          </body>
      </html>

systemjs.config.js

var map = {
    'app':                        'app', // 'dist',

    '@angular':                   'node_modules/@angular',
    'angular2-in-memory-web-api': 'node_modules/angular2-in-memory-web-api',
    'rxjs':                       'node_modules/rxjs',
    'css-animator':               'node_modules/css-animator'
  };
   var packages = {
    'app':                        { main: 'main.js',  defaultExtension: 'js' },
    'rxjs':                       { defaultExtension: 'js' },
    'angular2-in-memory-web-api': { main: 'index.js', defaultExtension: 'js'   },
     };
     System.config(config);

custom.animate.directive.ts

import {Directive, ElementRef, Renderer} from '@angular/core';
 import {AnimationService, AnimationBuilder} from 'css-animator';

 @Directive({
    selector: '[login-method]',
    host: {
      '(click)':'onClick()'
   }
})

export class LoginOptionsDirective{
   private animator : AnimationBuilder;

   constructor(animationService: AnimationService, private el: ElementRef, private renderer: Renderer){
      this.animator = animationService.builder();
  }

  onclick(){
      this.renderer.setElementStyle(this.el, 'color','black');
      console.log(this.el.nativeElement.getAttribute("login-method"));
   }
 }

I encountered errors like

animation_builder.js:434 Uncaught ReferenceError: exports is not defined
and
localhost/:18 Error: Error: XHR error (404 Not Found) loading http://localhost:3000/node_modules/css-animator(…)
on the browser console.

Seeking assistance to resolve these issues. Any help would be much appreciated!

Thank you.

Answer №1

When you directly include animation_builder.js in the <head> section:

<script src="node_modules/css-animator/builder/animation_builder.js"></script>

You might encounter a ReferenceError, as the individual files in the css-animator package are compiled to CommonJS format, which is not native to browsers.

Consider deleting that line and let SystemJS handle file loading automatically when importing them elsewhere. SystemJS is compatible with CommonJS.

Alternatively, you can add the SystemJS bundle provided by the package in the <head> section. By doing this, if you import a module from css-animator, SystemJS will already have it registered for quick loading.

You have the option to include either the minified or unminified bundle like so:

<!-- Unminified Source -->
<script src="node_modules/css-animator/bundles/css-animator.js"></script>

<!-- Minified Source -->
<script src="node_modules/css-animator/bundles/css-animator.min.js"></script>

Just a heads up: I’m the creator of this package.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Adding a cell break line within AG-GRID in an Angular application

I'm trying to display two sets of data in a single cell with ag-grid, but I want the data to be on separate lines like this instead: Data with break line I attempted to use "\n", "\r", and "\br" but it didn't work. Here is my code ...

Retrieve the value from an HTML class using Angular

The Person Object has a field called schoolId, but the School object (not shown here) contains the schoolName. I want to display the schoolName in the table data cell instead of the schoolId from the Person Object. How can I achieve this? <tr *ngFor=& ...

How to retain the side menu icon in Ionic 2 even after navigating using navCtrl push

Whenever I navigate to a new page using navCtrl.push, the sidemenu icon (hamburger) disappears and is replaced by a back button instead of coexisting with it. What I am aiming for is to retain the sidemenu icon by positioning it on the right side of the i ...

Problem with RxJS array observable functionality not meeting expectations

I am struggling with an Angular service that contains an array of custom objects and an observable of this array. An external component subscribes to the observable but does not respond when the list is modified. Additionally, the mat-table, which uses the ...

What is the correct way to refer to "this" within an Angular2 component template?

I'm working with an Angular2 component that looks like this: class A { filter(..) } Within the template for A, I have <.. list | pipe:filter ..> The issue arises when I call filter inside of the pipe - I don't have access to "this" w ...

Navigating Between Components in Angular: How to Redirect from One Component to

As I delve into learning angular Routing and Navigation, I find myself stuck at the navigation part. This is the structure of my Angular Components: AppComponent -LandingPage -WhatEver1 -Home -Price -Sales -WhatEver2 -Blog ...

Embed the div within images of varying widths

I need help positioning a div in the bottom right corner of all images, regardless of their width. The issue I am facing is that when an image takes up 100% width, the div ends up in the center. How can I ensure the div stays in the lower right corner eve ...

Retrieve data that resets to undefined upon reloading from an array

Encountering an unusual error while working with TypeScript for the first time. Initially, when I use console.log(data), it displays an array with objects. However, upon reloading the webpage without making any changes, the console log shows undefined. con ...

The first click does not trigger the update for the md-autocomplete

After successfully implementing md-autocomplete in my Angular4 app, I encountered a problem where the options do not show up when the list is first clicked, unlike in the demo. The options only appear once a selection is made. Here is the HTML code: &l ...

What is the process to enable mandatory validation after a change in input in Angular 4?

Currently, I am working on a project using Angular 4. One of the tasks I need to achieve is validation. <input [(ngModel)]="someModel" required placeholder="some placeholder"/> The validation triggers immediately, but I want it to only trigger aft ...

The protractor tool is unable to recognize an Angular component when it is displayed on the page

I have implemented end-to-end (e2e) testing on my project, but I am facing issues that are causing my tests to fail. Below is a snippet of my app.po.ts file: import { browser, by, element } from 'protractor'; export class AppPage { public b ...

Testing the Binding of Models in Angular 5 Using Jasmine Framework

I'm currently working on writing a unit test to verify that the JSON data returned from the components method call successfully links to a TypeScript model. Here's what my model looks like: export interface IPlayerAccount { playerId: number; ...

How to Pass a JSON Object to a Child Component in Angular and Display It Without Showing "[Object

Need help with my API call implementation. Here's a snippet from my Input component: Input.html <form (submit)="getTransactions()"> <div class="form-group"> <label for="exampleInputEmail1"></label> <input type="t ...

Performing an Axios POST request in a React Native and React app using JSON.stringify and Blob functionality

I am currently developing an application where I have encountered an issue when calling an API endpoint in react native. Interestingly, the web app (built with React) does not encounter any errors. Here is the code for the web app using React with TypeScri ...

Getting the specific nested array of objects element using filter in Angular - demystified!

I've been attempting to filter the nested array of objects and showcase the details when the min_age_limit===18. The JSON data is as follows: "centers": [ { "center_id": 603425, "name" ...

Issue with Angular Material Auto Complete not selecting items when filtered

Encountered a problem with the mat-autocomplete control in Angular Material where it fails to include the CSS class "mdc-list-item--selected" on the mat-option and also does not add the mat-pseudo-checkbox to a selected option when the contents are display ...

Is it possible to alter the color of an SVG icon when it is used in conjunction with <mat-icon> in Angular Material?

Trying to change the color of an svg icon displayed using Angular Material on hover has been a challenge for me. Here's my code snippet: <mat-icon svgIcon="menu"></mat-icon> The icon is visible, but when I attempt to add a class for chan ...

Angular: Smooth transitions for ngif animations - Learn how to animate ngif elements seamlessly as one element is removed from the DOM

Is there a way to delay the execution of ngIf? I have a scenario where elements in a parent component fade out and are removed from the DOM using ngIf, followed by elements from a child component coming in. However, I am facing an issue with elements overl ...

I am trying to replace the buttons with a dropdown menu for changing graphs, but unfortunately my function does not seem to work with the <select> element. It works perfectly fine with buttons though

I am currently working on my html and ts code, aiming to implement a dropdown feature for switching between different graphs via the chartType function. The issue I am facing is that an error keeps popping up stating that chartType is not recognized as a ...

Unable to apply the CSS styles on the webpage

I'm having trouble adjusting the CSS for a specific div with the class .cropper inside a component named image-cropper, and I can't figure out why it's not taking effect. Here is an image of the particular div. Below is the CSS code I atte ...