Having trouble getting the Angular 2 quickstart demo to function properly?

Just starting out with Angular 2, I decided to kick things off by downloading the Quickstart project from the official website.

However, upon running it, I encountered the following error in the console:

GET http://localhost:3000/node_modules/@angular/platf...-dynamic/bundles/platform-browser-dynamic.umd.js

304 Not Modified 87ms zone.js (line 2019) GET http://localhost:3000/systemjs-angular-loader.js 404 Not Found 2ms zone.js (line 2019)

"NetworkError: 404 Not Found - http://localhost:3000/systemjs-angular-loader.js" systemj...ader.js

Unhandled Promise rejection: Permission denied to access property "then" ; Zone: ; Task: Promise.then ; Value: Error: Permission denied to access property "then"

resolvePromise@http://localhost:3000/node_modules/zone.js/dist/zone.js:622:21

scheduleResolveOrReject/<@http://localhost:3000/node_modules/zone.js/dist/zone.js:716:17

ZoneDelegate.prototype.invokeTask@http://localhost:3000/node_modules/zone.js/dist/zone.js:367:17

Zone.prototype.runTask@http://localhost:3000/node_modules/zone.js/dist/zone.js:166:28

drainMicroTaskQueue@http://localhost:3000/node_modules/zone.js/dist/zone.js:546:25

ZoneTask/this.invoke@http://localhost:3000/node_modules/zone.js/dist/zone.js:424:25

Answer №1

Update your systemjs.config.js file with the following changes:

(function (global) {
  System.config({
    map: {
      'rxjs': 'node_modules/rxjs',
      '@angular': 'node_modules/@angular',
     'app': './app',
     'angular2-in-memory-web-api' : 'node_modules/angular2-in-memory-web-api'
   },
    packages: {
      'app': {
        main: 'main.js',
        defaultExtension: 'js'
      },

      '@angular/platform-browser': {
        main: 'bundles/platform-browser.umd.js'
      },

      '@angular/core': {
        main: 'bundles/core.umd.js'
      },

      '@angular/http': {
        main: 'bundles/http.umd.js'
      },

      '@angular/compiler': {
        main: 'bundles/compiler.umd.js'
      },

      '@angular/compiler-cli': {
        main: 'index.js'
      },

      '@angular/router': {
        main: 'bundles/router.umd.js'
      },

      '@angular/upgrade': {
        main: 'bundles/upgrade.umd.js'
      },

      '@angular/forms': {
        main: 'bundles/forms.umd.js'
      },

      '@angular/common': {
        main: 'bundles/common.umd.js',
        defaultExtension: 'js'
      },

      '@angular/platform-browser-dynamic': {
        main: 'bundles/platform-browser-dynamic.umd.js'
      },

      '@angular/platform-server': {
        main: 'bundles/platform-server.umd.js'
      },

      'rxjs': {
        defaultExtension: 'js'
      },

      'angular2-in-memory-web-api': {
        main: './index.js',
        defaultExtension: 'js'
      }
    }
  });
})(this);

Answer №2

It appears that the Angular.io team included systemjs-angular-loader.js in the Plunker links, but overlooked adding the file to downloadable projects.

Kindly ensure to add systemjs-angular-loader.js at the same level as systemjs.config.js

var templateUrlRegex = /templateUrl\s*:(\s*['"`](.*?)['"`]\s*)/gm;
var stylesRegex = /styleUrls *:(\s*\[[^\]]*?\])/g;
var stringRegex = /(['`"])((?:[^\\]\\\1|.)*?)\1/g;

module.exports.translate = function(load){

  var url = new URL(load.address);

  var basePathParts = url.pathname.split('/');

  if (url.href.indexOf('plnkr') != -1) {
    basePathParts.shift();
    basePathParts.shift();
  }

  basePathParts.pop();
  var basePath = basePathParts.join('/');
  load.source = load.source
    .replace(templateUrlRegex, function(match, quote, url){
      let resolvedUrl = url;

      if (url.startsWith('.')) {
        resolvedUrl = basePath + url.substr(1);
      }

      return `templateUrl: '${resolvedUrl}'`;
    })
    .replace(stylesRegex, function(match, relativeUrls) {
      var urls = [];

      while ((match = stringRegex.exec(relativeUrls)) !== null) {
        if (match[2].startsWith('.')) {
          urls.push(`'${basePath.substr(1)}${match[2].substr(1)}'`);
        } else {
          urls.push(`'${match[2]}'`);
        }
      }

      return "styleUrls: [" + urls.join(', ') + "]";
    });

  return load;
};

Source code retrieved from: https://angular.io/resources/live-examples/forms/ts/eplnkr.html

Answer №4

Upon reviewing the error log, it is evident that the issue lies within the first few lines:

GET http://localhost:3000/systemjs-angular-loader.js 404 Not Found 2ms  zone.js (line 2019)

This indicates that the file systemjs-angular-loader.js is missing from your project.

In a response by @TimFogarty on Stack Overflow, it is mentioned that systemjs-angular-loader.js is a new addition in Angular 4.0.

Given that the official documentation does not provide clarity on the contents of systemjs-angular-loader.js and Angular-CLI does not generate it either, the recommended course of action would be to obtain it from the official Angular Quickstart project.

For reference, here is the current version of the file:

var templateUrlRegex = /templateUrl\s*:(\s*['"`](.*?)['"`]\s*)/gm;
var stylesRegex = /styleUrls *:(\s*\[[^\]]*?\])/g;
var stringRegex = /(['`"])((?:[^\\]\\\1|.)*?)\1/g;

module.exports.translate = function(load){
  if (load.source.indexOf('moduleId') != -1) return load;

  var url = document.createElement('a');
  url.href = load.address;

  var basePathParts = url.pathname.split('/');

  basePathParts.pop();
  var basePath = basePathParts.join('/');

  var baseHref = document.createElement('a');
  baseHref.href = this.baseURL;
  baseHref = baseHref.pathname;

  if (!baseHref.startsWith('/base/')) { // it is not karma
    basePath = basePath.replace(baseHref, '');
  }

  load.source = load.source
    .replace(templateUrlRegex, function(match, quote, url){
      var resolvedUrl = url;

      if (url.startsWith('.')) {
        resolvedUrl = basePath + url.substr(1);
      }

      return 'templateUrl: "' + resolvedUrl + '"';
    })
    .replace(stylesRegex, function(match, relativeUrls) {
      var urls = [];

      while ((match = stringRegex.exec(relativeUrls)) !== null) {
        if (match[2].startsWith('.')) {
          urls.push('"' + basePath + match[2].substr(1) + '"');
        } else {
          urls.push('"' + match[2] + '"');
        }
      }

      return "styleUrls: [" + urls.join(', ') + "]";
    });

  return load;
};

Answer №5

In my current Angular project, running version 4.3.2 which is not the latest, I discovered that systemjs-angular-loader.js is missing from my package.json file. Surprisingly, I did not encounter the 404 error mentioned by the original poster. Could it be that systemjs-angular-loader.js has been relocated within the updated versions of Angular (perhaps in the 4.x.y series)?

Interestingly, when I removed moduleId: module.id from the @Component decorator in my app.component.ts file, the page failed to load properly. This alteration seems to suggest a modification in the codebase, possibly alluded to in the documentation changelog provided at . Strangely, this change was not explicitly detailed in the official Angular Changelog at https://github.com/angular/angular/blob/master/CHANGELOG.md, nor in the Getting Started guide. Despite scouring the Angular documentation, I could not locate any examples showcasing the transition from the old method to the new one.

The solution to this mystery must lie within the official Angular code documentation, complete with clear before-and-after examples for developers to follow. Once identified, I will be sure to reference it here for others facing the same dilemma.

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

What is the best way to combine two JSON objects within the same array based on their IDs located in another array?

I am dealing with a large JSON array that contains multiple objects and arrays. I need to combine two types of objects together. For example, numbers 1-10 represent "Froms" and numbers 11-20 represent "Tos". I want to merge Froms and Tos, displaying them ...

Choose a specific <div> element from an external page using Ajax/PHP

I'm encountering a small issue. I am currently utilizing Ajax to dynamically load content from another page into a <div> element after detecting a change in a <select>. However, my specific requirement is to only load a particular <div& ...

What is the best way to showcase information from an external API in react js?

As I develop my new app, I am integrating API data from . This feature will enable users to search for their favorite cocktail drinks and display the drink name fetched from the API on the page. However, I am encountering an error that says "Uncaught TypeE ...

Collaborative Animation Techniques for Modern Angular Versions (7 and up)

Can animation triggers be shared across the entire project? I'm hoping to avoid having to include an import and animation meta declaration in every new component. Appreciate any help on this! ...

What might be the underlying reason for Chrome displaying a net::ERR_FAILED error when attempting to make a request from a Vue frontend to a C# API using Axios?

I have a C# Backend+API that I interact with from my Vue Application using axios to make requests. In the C# code, there is an endpoint that looks like this: // GET: api/Timezone public HttpResponseMessage GetTimezoneData() { ...

What is the best way to distribute a function within a div container?

I'm currently working on a function that manages the show/hide functionality and position of tooltips: tooltip = (e) => { // show/hide and position of tooltip // retrieve element data } In addition, I have div elements whe ...

Do you want to reset the validation for the paper input?

I am encountering an issue with a paper-input element in my code. Here is what it looks like: <paper-input id="inputForValidation" required label="this input is manually validated" pattern="[a-zA-Z]*" error-message="letters only!"></paper-input&g ...

How Can You Create a Sliding List Animation (Up/Down) Using Angular and Twitter-Bootstrap?

Hey, can you give me a hand with this? :) I'm attempting to create a sleek sliding up and down list in Angular, but I'm struggling to make it work. My CSS skills are not very advanced, so I'm still learning and gave it my best shot: http:// ...

Structuring a TypeScript microservices repository on GitHub: Best practices to follow

Currently, I am in the process of designing a set of microservices. The structure I have been following involves each item having its own repository. my-project-logger my-project-numbers-service includes: my-project-logger type definitions + class obje ...

What could be the root of this next.js build issue occurring on the Vercel platform?

I recently upgraded my next.js project to version 12.0.7, along with Typescript (4.5.4) and pdfjs-dist (2.11.228), among other libraries. Locally, everything runs smoothly with the commands yarn dev for development and yarn build for building. However, af ...

Guide on accessing the fastify application instance within an imported module

Currently, I am working on developing a rest API using Fastify and I am in the process of organizing my code into separate files for better structure. One issue I am facing is how to access the Fastify instance within a file that I import. The following s ...

Learn how to extract precise information from a JSON array by utilizing Angular 6

After making a GET request in Angular 6, I successfully retrieved data from a JSON array. Now, I have this JSON data as an example and my goal is to find the team(s) that employee "TEST4KRWN" is part of. Can anyone guide me on how to write a JSON query us ...

Manipulating data in textarea using datatables

I am attempting to implement functionality where the clicked row in a datatables is added to a textarea. If the same row is clicked again, the data should be searched in the textarea and removed if found (select/deselect). When I select one row followed b ...

Present a Java-generated JSON object on a JSP page using JavaScript

Hello, I am currently working on creating a Json object in Java and would like to display the same JSON object in JSP using JavaScript. Essentially, I am looking to add two more options in my select box using Ajax. The Ajax is being called and I can see th ...

The webpage freezes when attempting to run jQuery with Selenium

I'm currently facing an issue where my selenium script hangs the webpage whenever I try to find an element using jQuery. The script doesn't execute and a pop up appears in the browser with the message "A script on this page may be busy, or it may ...

Discover the steps to obtain a READY status for your uploaded video using the Kaltura VPaaS API

After uploading the video, it will show as CONVERTING in the media status on the KMC dashboard. Eventually, it will change to READY. Is there a way for me to verify the status and make sure it is READY? ...

What sort of JavaScript WYSIWYG text editor provides formula support?

Looking for a Javascript rich text editor that offers formula selection in the toolbar. Any recommendations? ...

Start Transloco in Angular before the application begins

For our Angular project, we have implemented Transloco to handle translations. Within my typescript code, I am using the transloco service in this manner: this.translocoService.translate('foo.bar') I understand that it is crucial to ensure that ...

Preventing an infinite re-render loop caused by event listeners in React

One functional component is causing me some trouble: export default function Nav({photo}) { const [isOpen, setIsOpen] = useState(false) const [width, setWidth] = useState(window.innerWidth); const breakpoint = 768; useEffect(() => { ...

What could be causing my newsletter form to malfunction on Amazon CloudFront?

I'm currently working with HTML on an Amazon EC2 instance (Linux free tier). I want to integrate CloudFront into my setup, but I'm encountering issues with my newsletter functionality. Despite not being an expert in AWS, I am struggling to unders ...