Is it necessary for ts-node to check the baseUrl property in tsconfig.json?

Currently, I am working with ts-node and within my tsconfig.json, I have set the "baseUrl": "./src". With this configuration, I am able to import a sibling from the src directory without the need for the ./ prefix. However, it appears that ts-node is not utilizing the baseUrl property when resolving these sibling imports, resulting in errors like the one below:

    > [email protected] test /home/ole/Junk/tsmochanyc
    > mocha -r ts-node/register src/**/*.spec.ts

    Error: Cannot find module 'hello'
        at Function.Module._resolveFilename (internal/modules/cjs/loader.js:548:15)

I am wondering whether this issue is related to a bug in ts-node or if there is something else I should be doing differently to resolve it?

Answer №1

One solution to the problem mentioned in the ts-node issue can be found by using a package called tsconfig-paths. I have provided a complete (yet minimal) working example below for reference:

git clone https://github.com/oleersoy/tsmochanyc
cd tsmochanyc
npm i
npm test

To understand how the resolution works, take a look at the properties baseUrl and paths in the tsconfig.json file. In this setup, tsmochanyc acts as a proxy for src/, making the path structure consistent with what developers would use if tsmochanyc was an external dependency.

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

Displaying an iframe in Internet Explorer

My current setup involves a button that triggers the loading and printing of a report within an "invisible" iframe enclosed in a div. This process allows users to print the report from a different page without any visual disruption or changing pages, aside ...

Ways to ensure the security of a single page web application

As an example, if I am building a web application using AngularJS that stores sensitive user information such as credit card numbers. I am contemplating what security measures I should implement. Security is not my area of expertise so I feel lost when it ...

Using AngularJS to evaluate a string within a function in order to access a property within a JSON array

Unfortunately, I am struggling to come up with a specific title for what I am attempting to achieve. The issue at hand involves manipulating a JSON list within an angular framework. Below is an example of the structure: $scope.users = { // The ...

In JavaScript, the href action is triggered when navigating to a linked page

We have developed a unique eCommerce CMS that utilizes: <a href="javascript:AddToBasket(3471412104801);">Add to Cart</a> ...to enable adding a product to the cart (referred to as Site A). As we are in the process of creating a separate site ( ...

The <div> element is not displaying the JSON response when using Ajax

I have created a basic login form and I am attempting to validate it using an AJAX call. The validation process is successful, but the issue arises when the correct email or password is entered. Instead of displaying the JSON success or error message in a ...

"Encountering a getElementById reference error while working with React

Click here to access the code var Application = React.createClass({ render(){ return( <h1>Greetings from the virtual world!</h1> ) } }) ReactDOM.render(<Application />,getElementById('app-ar ...

Determining Cost Using Quantity and Option Changes in Angular 4

Task In the shopping cart, there is a list of items with options, quantities, and prices. The goal is to calculate the total price based on any changes in the quantity and option of an item. Investigation I included [(ngModel)] for 2-way data binding, ...

React is unable to locate the component element within the DOM

I'm attempting to set the innerHTML for the div element with the ID of ed. Unfortunately, I am unable to access it once React has finished rendering. It seems that this is due to the render stages, as I am receiving a null value for the div element. W ...

Switching from tables to using list items (li) in a shopping list can greatly enhance the

I have been using a program to create a shopping list with item names and prices using Tables. However, I now need to convert everything to lists in order to utilize appendChild() and createElement(). How can I accomplish this change in JavaScript? let ...

Guide on how to align h1 in the navigation bar

I've been attempting to center text on a nav bar but haven't been successful. What could I be overlooking? // include external modules import React, { Component } from "react"; import { Navbar } from "reactstrap"; import { Menu } from " ...

Array of materials for ThreeJS GLTFLoader

Attempting to load a model using GLTFLoader and apply different colors for each face of the object (cube) using a material array is not functioning as expected. var materials = [ new THREE.MeshPhongMaterial( {color: 0x552811,specular: 0x222222,shininess: ...

Navigating on a page using anchor tags within a dropdown menu

I'm in the process of creating a top navigation bar with dropdown functionality that appears when hovering over certain navigation items. Here's how it currently looks: $(document).ready(function(){ $('[data-toggle="tooltip"]').t ...

Creating a custom JSON structure in React.js to calculate and display monthly amounts

I retrieved data from my API with the following structure: [{…}, {…}, {…}, {…}, {…}] Each object contains detailed information like this: { date: "2018-01-01" import: 1 }, { date: "2018-03-03" import: "10" }, { date: "2018-03-20" impor ...

Obtaining the dimensions of each individual child component within an NgTemplate

I have the following code snippet within my template. While I can iterate through its components using `get`, it does not return an object that allows me to access deeper into the HTML attributes. <ng-template #container></ng-template> Compon ...

Incorporate the functionality of Drag and Drop for vertically sorting rows

Looking for a way to implement DRAG and DROP functionality on rows in my HTML code. <table> <tr class="table-header"> <th>Title</th> <th>Name</th> <th>Modified By</th> < ...

The Firebase Cloud Function assigned to a specific region is currently experiencing functionality issues

I'm faced with the challenge of invoking a Firebase Cloud Function that has already been successfully deployed from my Vue.js application. The specific requirement is for the function to be executed in the europe-west3 region. My approach involves cl ...

typescript makeStyles() functions from material-ui library

I've been struggling to find the correct type without relying on any. I have a working code that styles the component as expected: import { makeStyles } from '@material-ui/core/styles' const useStyles = makeStyles((theme) => ({ mainC ...

Node module @azure/functions was uninstalled following the deployment of Azure Functions using VSCode

Whenever I deploy my Azure Function app using VSCode, the @azure/functions node module keeps getting removed and the import statement displays an error stating that the module cannot be found. I am aware that this package is not necessary in Azure, but how ...

Validation of forms - Must include one particular word from a given set

I am in the process of utilizing Javascript to validate an input field with the specific formatting requirements outlined below: "WORD1,WORD2" The input must contain a comma separating two words, without any spaces. The first word (WORD1) can be any word ...

"Caution: The `className` property did not align" when configuring a theme provider within Next.js

I'm currently working on developing a theme provider using the Context API to manage the application's theme, which is applied as a className on the body element. The implementation of the context is quite straightforward. When initializing the ...