Unable to locate a custom definition for TypeScript v3

When I am running my webpack dev server, Typescript is generating this error:

ERROR in ./src/components/allowcated-resources/AllowcatedResources.tsx
Module not found: Error: Can't resolve 'my-scheduler' in 'mypath\allowcated-resources'
 @ ./src/components/allowcated-resources/AllowcatedResources.tsx 3:0-41 77:20-28
 @ ./src/components/App.tsx
 @ ./src/index.tsx
 @ multi ./src/index.tsx

This is the content of my tsconfig file:

{
  "compilerOptions": {
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": true,
    "allowSyntheticDefaultImports": true,
    "allowUnusedLabels": false,
    "allowUnreachableCode": false,
    "jsx": "react",
    "module": "ESNext",
    "moduleResolution": "node",
    "noImplicitAny": false,
    "target": "es5",
    "sourceMap": true,
    "lib": ["es6", "dom"],
    "typeRoots": ["./node_modules/@types", "./typings"],
    "baseUrl": ".",
    "paths": {
      "my-scheduler": ["typings/my-scheduler"]
    },
    "plugins": [
      {
        "name": "typescript-tslint-plugin",
        "alwaysShowRuleFailuresAsWarnings": false,
        "ignoreDefinitionFiles": true,
        "configFile": "./tslint.json",
        "suppressWhileTypeErrorsPresent": false
      }
    ]
  },
  "include": ["./src/**/**/*"],
  "exclude": ["node_modules", "typings"]
}

I have a directory named 'typings' in the root folder and it contains 'typings/my-scheduler/index.d.ts'

The content of index.d.ts file is as follows:

declare module 'my-scheduler' {
  // export members
  export class TimeSpan { // }
}

Even though I can locate this typing by clicking on vs code import,

import { TimeSpan } from 'my-scheduler';

However, when I run the web pack server, it gives me the following error:

Module not found: Error: Can't resolve 'my-scheduler'

What could be causing this issue?

Answer №1

You seem to be conflating two different methods of resolving modules - ambient external module declarations and standard module resolution using mechanisms like --paths and --moduleResolution.

Ambient external module declarations can cause issues by cluttering the global namespace with module declarations, and they typically look like this:

// This declaration will be available for import in TypeScript regardless of its file location

declare module 'my-scheduler' {
  export class TimeSpan {}
}

These declarations are not tied to specific file locations and become accessible once included in TypeScript's compilation context.

On the other hand, standard module resolution via paths ensures cleaner imports without polluting the global namespace, and it looks something like this:

export declare class TimeSpan {}

It is recommended to stick with the latter method when using paths as it functions like a regular module.

export declare class TimeSpan {}

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

The issue with Ajax success not functioning properly within nested .ajax calls

I encountered an issue with my nested ajax functions. The success code is triggered in the first ajax request (url: "get_hours.php"), but not in the second case (url: "send.php"). The code within "send.php" is executed correct ...

Cleanse the email using express-validator, but only if it is recognized as an email format; otherwise, disregard

Currently, I am developing an API that requires users to input their username and password for authentication purposes (login functionality). Users have the option to enter their email, username, or mobile number. To ensure consistency, I need to normalize ...

Compiling Vue with TypeScript: Troubleshooting common errors

Using Vue Components with Templates Multiple Times in TypeScript I am working on utilizing a component with a template multiple times within another component. The code is split between a .html file and a .ts file. The .html file structure is as follows: ...

The argument represented by 'T' does not align with the parameter represented by 'number' and therefore cannot be assigned

I am confused as to why, in my situation, <T> is considered a number but cannot be assigned to a parameter of type number. Changing the type of n to either number or any resolves the issue. Error: https://i.sstatic.net/h1GE9.png Code: const dropF ...

How to Transfer a jQuery Variable to a PHP script within a Modal using AJAX

I am currently facing an issue with retrieving the value of a variable and displaying it in a modal that is supposed to open. I have attempted to use the POST method but so far, no changes have occurred. Both sets of code are located within index.php. Her ...

The background image shifts dynamically with a parallax effect as the page is scrolled

I need help solving a parallax issue that I'm currently facing. On my webpage, I have a background image positioned at the top with a parallax effect achieved through background-position: fixed. However, I now require the image to scroll along with t ...

Is there a need to minify if the data will be compressed through gzip during

During the early days (yes, I'm really showing my age here), it was possible to reference scripts from a renamed zip file using this format: <script archive="path/to.jar" src="some.js"></script> This method was supported in IE4, NS4, and ...

Steps to create a clickable row with color change in Angular 4

How do I make an entire row clickable and change the row color when a checkbox is clicked? This is my HTML file: <section class="others"> <div class="sub-header">Others</div> <p class="text-center" *ngIf="otherTests.length === 0"> ...

Tips for Ensuring the Observable Completes Before Subscribing

I utilized RXJS operators in my code to retrieve an array of locations. Here is the code snippet: return O$ = this.db.list(`UserPlaces/${this.authData.auth.auth.currentUser.uid}`, { query: { orderByChild: 'deleted', equalTo: fal ...

How to initialize data in Vue.js components

I'm working on a Map.vue component and I need to update its data in Vue.js. However, I'm struggling to figure out how to do this: <template> <div> <div class="google-map" :id="mapName"> </div> </div> < ...

Tips on how to showcase JSON data retrieved from a RESTful API using JavaScript or jQuery

Is there a way to avoid repeating myself when displaying all content from my data array, like in the example below? // Program guide Rest $(document).ready(function() { $.ajax({ cache: false, url: "http://engrid2media.com/nextt/api/epg/s ...

Steps to activate ng-pattern exclusively when the field has been interacted with:

I've encountered a challenge with an input box that has an ng-pattern for link validation. Our project manager has requested that the text 'http://' be pre-filled in the input field, but doing so breaks the ng-pattern validation and prevents ...

Passing Props in Material-UI v5xx with ReactJS: A Beginner's Guide

Struggling with the fact that useStyle() isn't functioning properly in my material-UI v5xx version, I found myself at a loss on how to pass props in this updated edition. In Material-UI v4, it was as simple as: const Navbar = () => { const [open ...

How can one leverage Node JS to effectively manage events?

Is it considered a best practice to utilize events for communication between functions within ExpressJS? If so, what is the proper way to send arguments along with my emit event? ...

Accessing a model's field within an Ember.js each loop

Here is the code for a route that I am working on: Calendar.DateIndexRoute = Ember.Route.extend({ model: function(data) { return {arr:getCalendar(data), activeYear: data.year, activeMonthNumber: data.month, activeDay: data.da ...

Issue with checkbox click event binding in Angular 6 not functioning as expected

I am currently utilizing a reactive form to display a list of heroes to the user and would like to trigger a console log message when the user selects a hero by clicking on a checkbox. The issue I am encountering is that when I print this.form in the cons ...

Creating a static Top Bar that remains unaffected by page refreshing using Ajax or any other method can be achieved by implementing JavaScript and CSS

I've designed a sleek top bar for my upcoming website project. Below is the CSS code snippet for creating this clean div bar: .topbar { display:block; width:100%; height:40px; background-color:#f5f5f5; } I'm looking to incorporate a simple .SWF ...

Is it secure to send the one-time authorization code for Google+ Hybrid server-side flow over HTTP?

Hello, I have decided to transition from using Google's Client-side flow to the Hybrid server-side flow. Previously, I would send the client an access_token and then transfer it to the server to verify the user before logging them in or creating a new ...

Efficiency levels of reach = within angular instructions

Creating a directive can be done in various ways. Here is an example of how I structured mine: 'use strict'; myApp.directive('mySwitchOnOff', [ '$rootScope', function($rootScope) { return { restrict: 'C' ...

Having issues with rendering my images on Nuxt framework

In the midst of configuring the routing for my Nuxt project, I've encountered challenges with nesting specific folders to achieve a route structure like this: "/PageAccueil/PricingPage/Checkout123". The issue arises when attempting to place the "Pric ...