Angular 7 ERROR: The SystemJS reference is missing

In the process of developing an Angular 7 project with systemjs for dynamic module loading, I encountered an issue.

Upon attempting to utilize it, I encountered the following error:

 ERROR ReferenceError: SystemJS is not defined

Within my package.json file, the version of systemjs specified is 2.1.1

In order to address this, I included the path to system.js in the scripts section of my angular.json file

"./node_modules/systemjs/dist/system.js"

To make use of SystemJs within my service, I declared it as follows:

declare const SystemJS;

The implementation of SystemJs within a function looks like this:

loadModuleSystemJS(moduleInfo: ModuleData): Promise<any> {
    const url = this.source + moduleInfo.location;
    SystemJS.set('@angular/core', SystemJS.newModule(AngularCore));
    SystemJS.set('@angular/common', SystemJS.newModule(AngularCommon));
    SystemJS.set('@angular/router', SystemJS.newModule(AngularRouter));
    SystemJS.set('@angular/platform-browser/animations', SystemJS.newModule(BrowserAnimations));

    // now, import the new module
    return SystemJS.import(`${url}`).then((module) => {
      return this.compiler.compileModuleAndAllComponentsAsync(module[`${moduleInfo.moduleName}`]).then(compiled => {
        return module;
      });
    });
  }

If there's anything that I've overlooked, any guidance on resolving this issue would be greatly appreciated.

Answer №1

Make sure to incorporate the following version for optimal results: https://github.com/systemjs/systemjs/releases/tag/0.21.5 Based on my understanding, version 2.1.1 is not compatible with previous APIs. Interestingly, the example provided in the earlier response utilizes "0.21.4 Dev" instead.

Answer №2

For more information on this topic, I provided a detailed response in the corresponding github issue: https://github.com/systemjs/systemjs/issues/1940#issuecomment-490280011

In summary, previous versions of systemjs (systemjs@<2) utilized a global variable window.SystemJS, while newer versions (systemjs@>=2) do not have this. It is recommended to use window.System or simply System instead of SystemJS. Additionally, it is important to refer to the instructions outlined in the systemjs readme regarding ensuring that your webpack configuration does not interfere with System.import() calls.

Answer №3

Starting from Angular 6, it is necessary to specify the absolute path from the node_modules directory. The format should be similar to the following:

{
  ...
  "projects": {
    "example": {
      ...,
      "architect": {
        "build": {
          ...
          "options": {
            ...
            "scripts": [ "node_modules/systemjs/dist/system.js" ]
          },
          ...
        },
        ...
      }
    }
  },
  ...
}

For a real-life example, you can check out this Sample StackBlitz.

Please note that in my usage of this setup, I have implemented it within the app.component.ts file where I am logging the typeof SystemJS.set.

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

Tips for creating an HTTP only cookie in NestJS

Currently, I am in the process of incorporating JWT authorization with both an accessToken and refreshToken. The requirement is to store these tokens in HTTP-only cookies. Despite attempting this code snippet, I have encountered an issue where the cookies ...

Troubleshooting Cross-Origin Resource Sharing (CORS) issues with Font Awesome font in

For a while now, I've been using Angular and Material without any issues. However, recently I encountered a problem that has me puzzled. When running my Angular app from IntelliJ, an error message appeared in the console. The error stated: Access to ...

ReactJS does not support merging multiple pages into one based on user button selection

My goal is to dynamically load a component based on the user's current page. List of Pages: Executables Shop In the main screen, there is a sidebar with two icons. The primary button should set the Executables Page and the second button should set ...

Unable to Remove Angular CLI from Ubuntu - Showing `0.083s to check for updates``

I'm having trouble removing Angular from my Ubuntu 18.04 system using the command: npm uninstall -g angular-cli or npm uninstall -g @angular/cli When I try, it just says: up to date in 0.083s Here's a screenshot of the terminal: http ...

Can you explain the purpose of this TypeScript code snippet? It declares a variable testOptions that can only be assigned one of the values "Undecided," "Yes," or "No," with a default value of "Undecided."

const testOptions: "Undecided" | "Yes" | "No" = "Undecided"; Can you explain the significance of this code snippet in typescript? How would you classify the variable testOptions? Is testOptions considered an array, string, or another d ...

Retrieving the input value using ref in Vue 3 and TypeScript

It appears to be a straightforward issue, but I haven't been able to find consistent Vue 3 TypeScript documentation on accessing an input field and retrieving its value from within a function. <template> <Field type="text" ...

Retrieve the value of a variable to access an object property dynamically in React Native using TypeScript

As I attempted to create dynamic styles for this component, my goal was to determine the styles based on a string passed in as a property. Here is the code snippet: export type MyComponentProps = { styleName: string; } const MyComponent = (props: MyComp ...

Looking for help with setting up Nodemailer and installing it via NPM

I am currently developing a mobile application using Ionic with Angular/Typescript, and I'm in need of a front-end solution to dynamically send emails in the background to a specific email address. I tried using emailjs, but it requires JavaScript whi ...

The Lenis smooth scrolling feature (GSAP) is not functioning properly

I have encountered an issue with the smooth scrolling feature of gsap causing a delay on my website. This problem is only resolved when I manually go into the browser settings and disable smooth scrolling by navigating to chrome://flags/#smooth-scrolling ...

Using a pipe to display the length of an array in Angular 4 using *ng

I'm struggling with displaying a "No Records Found" message in my app that features a range slider. Whenever the range slider is dragged, the results are updated based on the value of "sliderPipe". Despite this, I am unable to show the message when no ...

How to conceal a column in an Angular Material table

Here is my Angular 2 material table setup: <mat-table #table [dataSource]="dataSource" > <!--- Note that these columns can be defined in any order. The actual rendered columns are set as a property on the row definition" -- ...

Adding or subtracting values in Angular framework to manipulate numbers

I am looking to increment a number from 1 to 50. I attempted to use the following code, but unfortunately the function is not working properly. See Demo Here Here is the HTML: <Button text="+" (tap)="plus()"></Button> <Button text="-" (t ...

Create a simulated class to serve as a property within a service

Currently, I'm working on an Ionic application and have created an AlertService class with two properties: messageAlert: Alert; errorAlert: Alert; The Alert class belongs to the Ionic framework, so I cannot modify it. To mock the Alert class, I came ...

Upon clicking the save button, the FormArray does not trigger the display of any mat error

When I click on the save button outside of the form, I want to display a mat error. However, the error is not getting displayed. I have tried using this.form.markAsDirty() and this.form.markASTouched(), but none of them seem to work. <form [formGroup ...

Tips for simulating a "nested" angular service within a component using jest

I'm looking to create a unit test for an Angular Component using Jest. The component, which is built on Angular version 7.2.0, interacts with a nested service through this.api.manageUser.getUsersStats(). My goal is to verify if this method is being ca ...

Content that is displayed by default for ng-content when utilizing ngIf

I have created an Angular 9 component called inner: <div #ref> <ng-content select="[content]"></ng-content> </div> <ng-container *ngIf="!ref.hasChildNodes()"> <div>Default value</div> &l ...

What is the best way to integrate Sass into a Create-React-App project that is using TypeScript

After setting up a new project using create-react-app and typescript, I included a sass file in my project as per the documentation (which mentioned built-in support for sass files). However, when trying to compile, I encountered the following error relate ...

Why is ASP.NET Core returning an empty object in the response?

Upon debugging the code in VS, I noticed that the cities list I am returning contains 3 objects with properties. However, when I call the endpoint, I receive a response of 3 empty list items. How can I resolve this issue? Model Class: public class City ...

directive for a custom loader in ag-grid

I have incorporated ag-grid-angular into my project more than 20 times across different pages. Each time, I use a custom loader before the data is loaded. However, I would like to make this custom loader a directive so that it can be easily reused in all i ...

Using WebSockets in Angular 4

Currently in the process of developing a chat application using Angular 4 and WebSocket. I found guidance from this Angular WebSocket tutorial This is the source code for the WebsocketService: import { Injectable } from '@angular/core'; import ...