Having trouble importing the hash-set module in TypeScript/SystemJS?

In the midst of developing an Aurelia project with TypeScript to generate JavaScript, I decided to incorporate another custom library called 'hash-set' (installed using jspm install npm:hash-set --save). However, I encountered difficulties in actually utilizing this package with SystemJS as the loader.

Here is a glimpse of my document structure:

\
dist\
    src\
        app.html
        app.js
        main.js
jsp_packages\
    npm\
        <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1b737a687336687e6f5b2a352b352a">[email protected]</a>\
node_modules\
index.html
config.js
package.json
tsconfig.json

The essential files include:

index.html

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Test</title>
  </head>

  <body aurelia-app="src/main">

    <script src="jspm_packages/system.js"></script>
    <script src="config.js"></script>
    <script>
      SystemJS.import('aurelia-bootstrapper');
    </script>
  </body>
</html>

app.ts This file compiles to app.js during the prebuilt step and utilizes es2015 as the target configuration.

import {hashSet} from 'hash-set';

export class App {
  public myText: string;
  hashFn(value) {
    return value.toString();
  }

  constructor() {
    alert("oh");
    const h = hashSet;
    const StringSet = hashSet(this.hashFn);
    alert('oh2');
  }
}

config.js

System.config({
  defaultJSExtensions: true,
  transpiler: false,
  paths: {
    "*": "dist/*",
    "github:*": "jspm_packages/github/*",
    "npm:*": "jspm_packages/npm/*"
  },
  meta: {
    "bootstrap": {
      "deps": [
        "jquery"
      ]
    }
  },
  map: { /*lots of aurelia and other library stuff*/
    "hash-set": "npm:<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bcd4ddcfd491cfd9c8fc8d928c92fcdcdce"></a>"
    }
  }
});

It's also specified in package.json as

{"jspm":{"dependencies":"hash-set": "npm:hash-set@^1.0.1"}}}

Upon running the code mentioned above (where typescript compiles to app.js during the prebuilt step), the app.js/app.ts loads accordingly. However, "oh" is displayed during construction but "oh2" never shows. On debugging, it seems that "hashSet" is undefined. This leads me to believe that systemjs might not be including the hash-set correctly. Am I overlooking something?


EDIT: While examining the generated js (app.js) file, I noticed something peculiar:

define(["require", "exports", "hash-set"], function (require, exports, hash_set_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    class App {
        hashFn(value) {
            return value.toString();
        }
        constructor() {
            alert('oh');
            const h = hash_set_1.hashSet;
            const StringSet = hash_set_1.hashSet(this.hashFn);
            alert('oh2');
        }
    }
    exports.App = App;
});
//# sourceMappingURL=app.js.map

During debugging, hash_set_1 matches the type I expect hash_set_1.hashSet to be. Modifying the javascript manually to use hash_set_1 instead of hash_set_1.hashSet resolves the issue.

Attempting import hashSet from 'hash-set'; (note the absence of {}) alters the offending line in the generated javascript to

const StringSet = hash_set_1.default(this.hashFn);
, which is still incorrect as "default" is not defined either.

Answer №1

Upon examining the code, it's clear that it is exported in the following manner:

module.exports = function hashSet(hashFn) {

Attempting to use

import { hashSet } from 'hash-set';
will not work since the export should be module.exports.hashSet = ....

The correct way to import it would be:

import hashSet = require("hash-set");

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

Error: express is missing a closing parenthesis for the argument list

When running this code in the VS Code terminal, be sure to verify any errors that may occur. var express = require('express'); var app = express(); app.get('/', function(request, response) { response.send("hello world"); }); app.li ...

Error message: ParseError: Received an unexpected character '<' while running tests using AVA

Initially encountering an issue within the project built on nuxt, I attempted to resolve it by creating a new project using vue-cli and re-installing AVA via npm. However, this did not have any effect on the problem at hand. Upon researching, I came across ...

Optimal method for retrieving data from a JSON object using the object's ID with a map

Can you teach me how to locate a json object in JavaScript? Here is a sample Json: { "Employees" : [ { "userId":"rirani", "jobTitleName":"Developer", "preferredFullName":"Romin Irani", "employeeCode":"E1", "region":"CA", "phoneNumber":"408-1234567", " ...

Developing secure web applications using Node.js and Express with HTTPS encryption

I am attempting to utilize express with node.js using https. Below is the relevant code for this segment: var express = require("express"); var app = express(); var https = require('https'); var privateKey = fs.readFileSync('./sslcert/myke ...

The map function is mistakenly returning double the amount of the object it should be returning

My program is fetching data from an API, but when I try to map the array for interesting data, it downloads the same object multiple times. For the first search, it downloads the object twice and for subsequent searches, it downloads the object six times. ...

The system encountered an error while trying to access the file "/box/main.c" because it does not exist in the directory

Currently, I am working on a project that requires the use of judge0 API. Initially, everything was running smoothly when I utilized it with RapidAPI. However, I made the decision to switch to a self-hosted setup using a docker-compose.yml file. While my ...

Using TypeScript, what is the best way to call a public method within a wrapped Component?

Currently, I'm engaged in a React project that utilizes TypeScript. Within the project, there is an integration of the react-select component into another customized component. The custom wrapped component code is as follows: import * as React from " ...

Issue: The hydration process has failed due to a discrepancy between the initial UI and the server-rendered content when utilizing the Link element

Exploring Next.js, I stumbled upon the <Link/> component for page navigation. However, as I utilize the react-bootstrap library for my navbar, it offers a similar functionality with Nav.Link. Should I stick to using just Link or switch to Nav.Link? ...

Trigger a modal to open based on a specific condition

I have successfully implemented a default modal from Materialize, but now I am looking to add a conditional opening feature to it. In my application, there is a countdown timer and I want the modal to automatically appear when the countdown reaches a certa ...

Utilizing a checkbox within a select dropdown component in Vue

Has anyone come across a checkbox dropdown feature in Vue? I have been searching online but couldn't find any examples or resources related to this. If someone has a working skeleton for it, please share! ...

Swapping out data points using JQuery

What could be causing line 10 to return null? Click here for the code file The code seems to function properly with line 40, but not with line 10. ...

Issue with scrolling to the bottom of collapsed sections in Bootstrap

I have a bootstrap collapse panel and I've added a toggle link at the bottom to allow users to expand and collapse the content with a click. The Issue My problem arises when the menu expands, causing it to scroll all the way to the bottom of the pag ...

Instantiate the component array upon object instantiation

I'm currently in the process of learning Angular 2, so please bear with me if this question seems trivial. I am attempting to create a dynamic form that can be bound to a model. However, I am encountering an issue where I am unable to initialize my ar ...

Retrieve the weekday dates for a specific year, month, and relative week number using Javascript or Typescript

I am in need of a custom function called getDaysOfWeekDates that can take a year, a month (ranging from 0 to 11), and the week number of each month (usually 4-5 weeks per month) as parameters, and return a list of dates containing each day of that particul ...

Forecast the width of an element using JavaScript

Is there a way to display tab elements on a webpage without them automatically wrapping into a new row if there are too many? Instead, I would like an arrow icon to appear at the end of the tabs so users can cycle between tab groups. The challenge is that ...

Stopping unauthorized users from manipulating REST URLs

I am currently exploring methods to prevent an exploit where a user manipulates the URL, specifically in a GET request scenario. The following code represents a route on my Express router that processes incoming requests for a certain collection "A" and re ...

Load Angular component on demand with necessary dependencies

Searching for an elegant solution (without resorting to private APIs) to create a widget-style dashboard. The goal is to dynamically load components based on user role. Is there a way to import a component and its dependencies included in the component&ap ...

The error message "Property 'list' is not found on type 'void' React - Material UI" indicates that the 'list' property is not recognized

Currently, I am facing an issue while working with Material UI and React Typescript. The error message I receive is "Property 'list' does not exist on type 'void'" when attempting to use makeStyles and createStyles to remove padding. It ...

Retrieve progress with easing using jQuery's animate() function

At the moment, I'm utilizing this code to create an animation for a bar-graph-inspired element: $('.anim').animate({ right: `${100-(e/max*100)}%`, backgroundColor: colors[0] },{ duration: 1500, easing: 'easeInQuart&apos ...

Is there a way to utilize javascript std input/output in repl.it effectively?

I created a straightforward program that calculates the factorial of a specified number, and I am interested in running it on repl.it. During its execution, I would like to interact with standard input and output through the command line. Is there a way ...