Why is there an error being thrown with this Typescript declaration?

I'm currently in the process of familiarizing myself with Typescript. Specifically, I am developing an Angular 2 application using typescript 2 and employing SystemJS 0.15.31 as my module loader.

My goal is to establish constants that are accessible throughout my entire application by defining them in a single file and importing them into individual components when necessary. Here's what I've implemented:

root/systemjs.config.js

System.config({
    map:{
        'app': 'dist',
        'config': 'dist/config',
        ...
    }
});

root/dev/config.ts

export module Config {
    var version:string = '1';
}

root/dev/app/app.component.ts

import {Config} from 'config';
...
export class AppComponent {
    ...
    version = Config.version;
}

However, after transpiling to Javascript and placing the .ts files in dist/, I encounter an error displayed by the typescript compiler on the first line of app.component.ts. Additionally, in the browser, the AppComponent does not recognize Config.version.

error TS2307: Cannot find module 'config'.

What could be causing this issue with my syntax?

Answer №1

It appears that SystemJS is anticipating dist/config to be a directory, not a file.

To resolve this issue, you should add a file extension to the path:

map: {
    ...
    'config': 'dist/config.js' 
    ...
}

By the way, export module is not valid in TypeScript. Perhaps you meant:

export const Config = {
   ...
}

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

Issue with synchronization: Delay execution until all fs.readFile calls have finished

I am facing a challenge where I need to extract columns from multiple CSV files and combine them into an array. My current approach involves using fs.readFile to read the CSV files and a callback function that processes the data and adds a new element to t ...

Exploring the capabilities of Angular 6 with web components

Encountering a particular issue, I have an Angular 6 application with a routing system in place. My goal is to create a web component that encapsulates this application for usage within another web application. Following a tutorial, I made modifications ba ...

Transform JavaScript nested array into a tree structure for better organization

Can someone help me convert the given JavaScript object into a format that is compatible with PrimeNG Tree? Here is the input: { "com": { "ups": { "demo": { "a": 9 } } } } The expected outp ...

Unable to access CommonModule in Angular 10 component loaded dynamically

I'm currently working on a project using Angular. One of my methods involves dynamically creating a component, but I'm encountering difficulties when trying to use directives like ngClass and ngIf from the CommonModule within this component. Her ...

Comparing strings in TypeScript

After extensively studying string equality in JavaScript, I naturally assumed the same rules would apply in TypeScript. However, I am encountering a perplexing issue. I have two identical strings that do not produce equal results when using the == and === ...

Encountering a clash in Npm dependencies

I have been involved in a Vue project where I utilized Vue Cli and integrated the Typescript plugin. However, I encountered multiple vulnerabilities that need to be addressed. When I executed npm audit fix, it failed to resolve the dependency conflict: npm ...

Remove TypeScript annotations without any other code transformations (such as Stage 3 proposals) while keeping the original line breaks intact

I'm looking for a solution to strip out all TypeScript types and annotations from my TS 3.9 module without any additional transpilation, including private class fields like #foo, while preserving the original line breaks in the code. The project I&ap ...

Learn how to stay updated on changes to resolved route data in Angular 2 by subscribing

I'm currently facing an issue with a component that fetches data from a route upon loading. The problem I'm encountering is that whenever the data displayed by the component changes, the component does not update automatically unless I manually ...

What is the best way to distinguish between administrators and regular users in an Angular project?

I am embarking on a project using Angular and I plan to incorporate both an admin and a user section within it. Is there a way to effectively separate the admin area from the user area in Angular? Additionally, how can I differentiate the style files for ...

Sharing the label element as a prop in React component

I encountered the following code snippet: <div className="input-field"> <label htmlFor="timeObjective">Time Objective</label> <FrequencySet label='label'/> //HERE </div> My goal is to tra ...

Customize the style of Angular Material within an Angular component

In my Angular component, I am utilizing Material 2's <md-input-container>. I am looking to customize a specific class, such as .mat-input-wrapper, that is originally defined in Angular Material. However, my intention is for this customization to ...

"Utilizing Typescript with Angular NGRX, the actions$.pipe() method can lead to

I am currently facing an issue with ngrx/effects - specifically with a pipe being undefined. I have included a sample code snippet below that appears to be correct according to the compiler, but I am receiving an error in the browser stating that the pipe ...

Error in Angular 8: The type of '[object Object]' is an object, whereas NgFor only supports binding to Iterables such as Arrays

I recently started using Angular 8 and I'm dealing with an issue while trying to fetch data from an http get request. I am attempting to iterate through the data using *ngFor but unfortunately encountering this error. Any suggestions on how to resolv ...

What is the type of the props function in a Typescript/React functional component?

As a newcomer to React, I am exploring ways to modify this code without utilizing any form of the add function that is Dependency Injected into the component. Most resources suggest using the React mouse click event type, which only accepts one parameter ...

What is the best way to show and hide a tooltip message when the mouse enters and leaves an element?

I am facing an issue where the mouseleave event is not working as expected. Even though the mouseenter event works fine and displays a message, the message stays visible even after the pointer is removed. How can I fix this problem? .on("mouseenter" ...

Show the distinct values of a mat-select element that retrieves information from an Angular filtered dataSource

Working on an Angular 9 app where data is displayed using a mat-table and filtered based on certain fields. The issue I'm facing is that the dropdown menu shows duplicate values, which is expected since some values may be repeated in the dataset. The ...

Utilizing RxJs operators in Angular: utilizing async pipe and tap does not fill data

Here is a code snippet I've been working on: This snippet is written in Typescript: isDataSearch = false; getDatacollectionByID() { const params = { id: <some random ID>, }; this.metaData = this.dataService.getDatacollectionByID(par ...

Error encountered in Angular with Karma and Jasmine: The function this.Service.<foo> is not defined in the Lifecycle Hook

When running Karma and Jasmine tests using the npm run test -- --no-watch --no-progress command with Karma/Jasmine, an error is thrown: Chrome 92.0.4515.159 (Mac OS 10.15.7) LoginComponent should create FAILED TypeError: this.loggerService.onDebug is n ...

The Angular Custom Material theme in Angular 18 is lacking visibility for colors

I'm facing an issue with implementing a custom theme in Angular Material 3 for Angular 18. Despite my efforts, the theme doesn't seem to be applied correctly. Initially, I tried importing and applying the theme as usual but that didn't work ...

React component state remains static despite user input

I am currently in the process of developing a basic login/signup form using React, Typescript (which is new to me), and AntDesign. Below is the code for my component: import React, { Component } from 'react' import { Typography, Form, Input, But ...