What is the reason my Typescript import functions only when I include the statement "console.log(myImport)"?

I'm facing an issue while trying to load my Angular 1.5.2 app (developed with Typescript) using JSPM 0.17.0.

This is the structure of my HTML:

<!DOCTYPE html>
<html ng-app="MyApp">
  <head>
    <meta charset="utf-8">
    <title>My App</title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width">

    <link rel="stylesheet" href="index.css">

    <script src="jspm_packages/system.js"></script>
    <script src="jspm.browser.js"></script>
    <script src="jspm.config.js"></script>
  </head>
  <body>
    <main first-name="huh" last-name="what"></main>
    <script>
      SystemJS.import('app.ts');
    </script>
  </body>
</html>

In my ./app.ts file, I encountered an error in the following code snippet:

import $ from 'jquery'
import angular from 'angular'
import main from './components/main/main.ts';

module app {

    angular.module('MyApp', [
        'main'
    ])

}

// The above code throws "[$injector:nomod] Module 'main' is not available!"

However, upon making a slight modification as shown below, everything worked smoothly:

import $ from 'jquery'
import angular from 'angular'
import main from './components/main/main.ts';

module app {

     angular.module('MyApp', [
        'main'
    ])

    console.log(main);

}

// After adding the console log, the error disappeared.

I am curious as to why referencing the imported module explicitly with console.log(main) fixed the issue. Is there something wrong with how I'm importing modules?

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

Browse through different states by clicking on the <a> </a> tag

Is there a way to switch between states defined by $stateProvider when clicking on the <a> </a> tag? Below are the states I have set up: $stateProvider //region page States .state('page1', { url: "/pg1", ...

Can anyone guide me on implementing map key autocomplete in Java?

Looking to transform this Typescript code into Java. Here's the code snippet: type CompTypes = "Texture" | "Layer" | "Sound"; Map<CompTypes, Component> components; Any suggestions on how to achieve this in Java? ...

Assigning different data types with matching keys - "Cannot assign type '...' to type 'never'."

I have a question regarding my application, where I am utilizing values that can either be static or functions returning those values. For TypeScript, I have defined the static values along with their types in the following manner: type Static = { key1: ...

The new Date function is malfunctioning on Firefox

Could you please explain why this particular function is not functioning correctly in Firefox (V 34 latest)? It appears to be working successfully on all other browsers, but 'DatePosted' is displaying as Invalid Date. Do you have any insights on ...

ng serve issue persists even after resolving vulnerabilities

Can anyone assist me in resolving why I am unable to start my project after fixing 3 high vulnerabilities? I ran npm audit to identify the vulnerabilities and then used npm install --save-dev @angular/<a href="/cdn-cgi/l/email-protection" class="__cf_em ...

Animating Angular for particular conditions

My goal is to create unique animations for specific state changes in my AngularJS app. I found inspiration from this tutorial: https://scotch.io/tutorials/animating-angularjs-apps-ngview, which works well. However, I am aiming for the following animations: ...

Adjust the transparency and add animation effects using React JS

When working on a React project, I encountered an issue where a square would appear under a paragraph when hovered over and disappear when no longer hovered. However, the transition was too abrupt for my liking, so I decided to implement a smoother change ...

Sending multiple data values to the controller in Angular

Imagine having a dynamically added drop-down list in your HTML template: <button type="button" ng-click="addRow()" style="margin-bottom:5px;">Add cities </button> <div ng-repeat="city in cities"> <select ng-model="cities_$ind ...

Creating an Object with Quoted Key in JavaScript/Typescript for MongoDB's '$push' Feature

Struggling to format the data in order to add an element into a nested array within MongoDB. Currently attempting this in TypeScript: var data = {$push:{"foo.12.bar":{ prop1: prop1, prop2: prop2, // referenced values above this code snippet ...

Building NextJS with Typescript encountered an error while using @auth0/nextjs-auth0

I am currently facing an issue while trying to build my NextJS application using Typescript. The problem lies with the auth0/nextjs-auth0 package, causing persistent errors during installation. One specific error can be found at the following link: https: ...

Discovering how to access the console once an Electron app has been packaged

Just as the title implies, I have successfully created a node / angular application using electron. The application works perfectly when launched with the electron ./app command. However, after building it (using either electron-packager or electron-builde ...

Having trouble locating the module recommendations on my Angular 1.6 app while using Browserify

My app is not able to find suggestions.module even though it loads am-suggestions-lib.js. I am using angular 1.6 and browserify, but I can't figure out what I'm doing wrong. Here are all the relevant files: View the tree here suggestion.module. ...

How can I extend a third-party JavaScript library in TypeScript using a declaration file?

Currently, I am working on creating a .d.ts file for an external library called nodejs-driver. While I have been able to map functions and objects successfully, I am struggling with incorporating the "inherit from objects defined in the JS library" conce ...

Issue: anticipated ']' after statement in sanity in conjunction with nextjs

Struggling to retrieve data from Sanity in Next.js, but encountering an error that reads: "Error: expected ']' following expression." As a beginner in this, I've been trying to troubleshoot it, but I'm unsure of the root cause of the er ...

TS2305 error: The module "/node_modules/rxjs/Rx" does not contain the 'Subscribable' member to export

I am currently working on an Angular 5 project and here is the package.json file: { "name": "ff-client", "version": "0.2.0", "license": "", ... } After installing npm and angular-cli, I ran npm install to get the required modules. However, when I ...

Angular 2 introduces one-way binding, which allows for modifications to be applied to both objects

How does one-way binding modify both objects? <component2 [obj]="obj1"></component2> Is there a way to make changes to obj without affecting obj1? It seems that only duplicating obj solves this issue. Is there another method in angular2 to a ...

Avoiding the pitfalls of hierarchical dependency injection in Angular 6

Too long; didn't read: How can I ensure that Angular uses the standard implementation of HttpClient in lower level modules instead of injecting a custom one with interceptors? I have developed an Angular 6 library using Angular CLI. This library expo ...

Sending the dot character as a parameter in AngularJS $http requests

I am attempting to pass the character . (dot) as a string in my Nodejs API call. I am utilizing the AngularJS $http object. Upon inspecting, I can confirm that the API call is indeed being made with the dot (.) character that I inputted in the search box. ...

Start Your Sentences with an Exclamation Point using an AngularJS Filter

When working with AngularJS, I encountered an issue while filtering a list of objects using ng-repeat: <tr ng-repeat="application in page.applications | filter: {DisplayName:page.ApplicationSearchValue}"> {{application.DisplayName}} </tr> ...

Ways to establish the relationship between two fields within an object

These are the definitions for two basic types: type AudioData = { rate: number; codec: string; duration: number; }; type VideoData = { width: number; height: number; codec: string; duration: number; }; Next, I need to create a MediaInfo typ ...