Having trouble importing ng-bootstrap via systemjs

Task Overview:

  1. Installing @ng-bootstrap/ng-bootstrap using npm install --save @ng-bootstrap/ng-bootstrap
  2. Attempted to load @ng-bootstrap/ng-bootstrap via systemjs, encountering an error: undefined is not an object (evaluating 'ng_bootstrap_1.NgbModule.forRoot')
  3. Importing NgbModule in the main module: import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
  4. Calling NgbModule.forRoot() in the imports section of the main module

I encountered an error when trying to call NgbModule.forRoot() - undefined is returned immediately after the import.

I also tried configuring systemjs:

(function(global) {
    var map = {
        app: 'app',
        '@angular': 'lib/@angular',
        'rxjs': 'lib/rxjs',
        '@ng-bootstrap/ng-bootstrap': 'https://npmcdn.com/@ng-bootstrap/ng-bootstrap'
    };

    var packages = {
        app: {
            main: './bootstrap.js',
            defaultExtension: 'js'
        },
        rxjs: {
            defaultExtension: 'js'
        },
        '@ng-bootstrap/ng-bootstrap': {
            main: './bundles/ng-bootstrap.js',
            defaultExtension: 'js'
        }
    };

    var ngPackageNames = [
        'common',
        'compiler',
        'core',
        'forms',
        'http',
        'router',
        'platform-browser',
        'platform-browser-dynamic'
    ];

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

    });

    System.config({
        defaultJSExtension: true,
        transpiler: null,
        packages: packages,
        map: map
    });
})(this);

I also made changes to app.module.ts:

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { RouterModule } from '@angular/router';
import { HttpModule, RequestOptions } from '@angular/http';
import { LocationStrategy, HashLocationStrategy } from '@angular/common';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';

import { AppComponent } from './app.component';
import { AppRoutes } from './app.routes';

import { HomeModule } from './home/home.module';
import { AuthenticationService } from './authentication/authentication.service';
import { AuthenticationModule } from './authentication/authentication.module';
import { ArticlesModule } from './articles/articles.module';

@NgModule({
imports: [
    BrowserModule,
    HttpModule,
    FormsModule,
    AuthenticationModule,
    ArticlesModule,
    HomeModule,
    RouterModule.forRoot(AppRoutes),
    NgbModule.forRoot()
],
declarations: [
    AppComponent
],
providers: [
    AuthenticationService
],
bootstrap: [AppComponent]
})

export class AppModule { }

Lastly, my tsconfig settings:

{
"compilerOptions": {
    "target": "es6",
    "module": "system",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": false
},
"exclude": [
    "node_modules"
]
}

Answer №1

We encountered a similar issue in our project.

After some investigation, we discovered that the issue only occurred when compiling with es2015 as the target. Switching it to es5 resolved the problem for us. You might want to give it a try as a temporary fix.

"target": "es5",
    "module": "commonjs",
    "declaration": false,
    "removeComments": true,
    "noLib": false,
    "lib": [
      "es2016",
      "dom"
    ],

It appears that there may be a compatibility issue with @ng-bootstrap and SystemJS.

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

Is there a way to integrate a MySQL database with parcel-bundler in a Node.js environment, or is there a simpler method to achieve this database integration with parcel-bundler?

Node.js and parcel-bundler are new to me, but I've managed to create a server.js file that connects to the database without any issues. Server.js const express = require('express'); const mysql = require('mysql'); //Establish con ...

Is the next function triggered only after the iframe has finished loading?

First and foremost, I understand the importance of running things asynchronously whenever possible. In my code, there exists a function known as wrap: This function essentially loads the current page within an iframe. This is necessary to ensure that Jav ...

Updating label values to default in JavaScript/jQuery

I need to utilize jQuery/js for the following tasks: Extract label values from form inputs Insert those labels as input values in the corresponding fields Conceal the labels It's a simple task. Instead of manually entering each label like this: $( ...

Removing a specific MySQL row using HTML in collaboration with Node.js

I've been working on a feature to allow users to delete specific rows from a table. Each row has a "Delete" link at the end, but when I click it, nothing happens. There are no errors displayed, and the console shows that 0 row(s) have been updated, ye ...

Transform a protractor screenshot into a PDF file

I'm currently working on a small Protractor code that captures screenshots, but my goal is to save these screenshots as PDF files. Below you can find the code snippet I have written. await browser.get(url); const img = await browser.takeScreenshot(); ...

Leveraging D3.js in combination with Total.js and node.js

I have been attempting to utilize total.js in conjunction with D3 for creating a tree visualization. However, I am encountering issues when trying to download D3. This is what I do: npm install D3 Upon running the above command, I receive the following e ...

Unique style pattern for parent links with both nested and non-nested elements

I am in the process of designing a website and I have a specific vision for how I want my links to appear, but I am unsure of how to achieve it. Here is the desired outcome: a red link a green link a red link a green link … Below is the HTM ...

Validation of multiple fields on the server side using AngularJS

I am working on a form that requires server-side validation for multiple fields in a single request. After receiving the response, I aim to display validation messages accordingly. Here is an example of what I have: This snippet shows my HTML code: <d ...

Having trouble replicating the progressive response from the server in node.js

Hey there, I recently dipped my toes into the world of node.js and decided to give it a shot. Following Ryan Dahl's tutorial (http://www.youtube.com/watch?v=jo_B4LTHi3I) as my starting point, I reached a section around 0:17:00 where he explains how s ...

Using the Sequelize query string prefix to find data that starts with a specific value

I'm currently working on an autofill feature that takes a string input and provides a list of string suggestions. While using Sequelize's iLike:query, it retrieves all strings in which the queried string is present. However, my goal is to priori ...

To prevent the page focus from shifting, make sure to force click on a blank link

My question involves an empty link: <a href="#" id="stop-point-btn">+ add stop-point</a> This link is connected to a JavaScript function: $("#stop-point-btn").bind("click", addStopPoint); The JS function simply inserts content into a specif ...

Error occurred when trying to run 'npm run dev' on vite: Unable to access the file "node_modules/react/jsx-dev-runtime.js"

After successfully creating a Vite app, I encountered three errors when trying to run the app with npm run dev: [ERROR] Cannot read file "node_modules/react/jsx-dev-runtime.js": Access is denied. [ERROR] Cannot read file "node_modules/react/index.js": Acc ...

Launch an Outlook window from within an Angular controller

This code snippet is functioning correctly: HTML code <a href="mailto:?subject={{vm.property.address.streetNumber}}, {{vm.property.address.streetName}} {{vm.cityName}} {{vm.stateName}}%20IPL%20#%20{{vm.property.id}}&body={{comment.note}}">@L("C ...

Ways to change the color of a button when it is clicked?

I am attempting to change the color of a button on another button click, but it doesn't seem to be working. function show_col(){ console.log("hello"); var path=localStorage.getItem(".physics_section #color1 button"); $(''+ ...

What is the most effective way for AngularJS controllers to communicate with one another?

As I develop a controller, it must interact with another controller. However, I'm uncertain if this is achievable? HTML: <div data-ng-app="TestApp"> <div data-ng-controller="menuCtrl"> <ul> <li> <a data-ng-clic ...

Show a separate div in a block format if the data field contains a value

<span>{{pstCtrl.doctorProfile.boardCertification ? === 'Yes' : $yes.display-block}}</span> <span class="yes">Yes</span> span.yes { display:none; } In my Angular.JS project, the code snippet above is demonstra ...

Is the controller of a nested view in Angular UI router automatically considered a child of the parent view's controller?

My UI-Router setup includes a main view for products and two nested states below it. I want each nested view to have its own controller while also inheriting some basic information from the parent controller (productsCtrl). However, when attempting to acce ...

Is it possible to interchange image src once the page has finished loading?

My current dilemma involves an image that is being inserted into my website through a third-party script: <img src="https://example1.com/image1.png" id="image1"> What I am trying to achieve is replacing this initial image with another one, like so: ...

Ways to prevent users from manually inputting dates in date fields

I am currently developing an application and I need to prevent users from manually entering a date in the type=date field on the HTML page. I want to restrict users to only be able to select a date from the calendar display, which is in the format MM/DD/YY ...

Incorporate a customizable month option within a flexible calendar design

I'm working on creating a calendar that adjusts to different screen sizes for my website. The script I've implemented is as follows: <script type="text/javascript"> $(document).ready(function () { $(".responsive-calendar").responsiv ...