The bespoke node package does not have an available export titled

No matter what I do, nothing seems to be effective.

I have successfully developed and launched the following module:

Index.ts :

import ContentIOService from "./IOServices/ContentIOService";

export = {
    ContentIOService: ContentIOService,
}

The file ContentIOService is structured as follows:

import {SuperIO} from "../Framework/SuperIO";
export interface ICMSContentData {
    id: number;
    url: string;
    htmlTag: string;
    importJSComponent: string;
    componentData: string
}

export interface CMSData {
    id: number;
    url: string;
    htmlTag: string;
    importJSComponent: string;
    componentData: Object
}

export default  class ContentIOService extends SuperIO {

    private static instance: ContentIOService;

    public static getInstance(): ContentIOService {
        if (!ContentIOService.instance) {
            ContentIOService.instance = new ContentIOService();
        }
        return ContentIOService.instance;
    }

    public async GetContent(url: string) {
        const response = await super.get<ICMSContentData[]>(url, {});
        try {
            if (response?.parsedBody) {
                return this.ProcessResponse(response.parsedBody);
            } else {
                this.handleHTTPError(new Error("Error"))
            }

        } catch (e) {
            this.handleHTTPError(e);
        }

    }

    private ProcessResponse(ContentData: ICMSContentData[]): CMSData[] {
        let CMSData: CMSData[] = [];
        for (let i = 0; i < ContentData.length; i++) {
            CMSData.push({
                id: ContentData[i].id,
                url: ContentData[i].url,
                htmlTag: ContentData[i].htmlTag,
                importJSComponent: ContentData[i].importJSComponent,
                componentData: this.parseComponentData(ContentData[i].componentData)
            })
        }
        return CMSData;
    }

    private handleHTTPError(e: Error) {
        console.log(e)
    }


    private parseComponentData(parseAbleString: string): Object {
        return JSON.parse(parseAbleString);
    }
}

After bundling everything together, it goes into a /lib folder:

https://i.stack.imgur.com/i1OGM.png

This creation process is based on the given tsconfig:

  {
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "declaration": true,
    "outDir": "./lib",
    "esModuleInterop": true,
    "strict": true
  },
  "include": ["src"],
  "exclude": ["node_modules", "**/__tests__/*"]
}

To cover all bases, here is my Package.json information:

    {
  "name": "sdk-io-package",
  "version": "1.1.6",
  "description": "",
  "main": "lib/index.js",
  "types": "lib/index.d.ts",
  "scripts": {
    "test": "jest --config jestconfig.json",
    "build": "tsc",
    "format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"",
    "lint": "tslint -p tsconfig.json"
  },
  "keywords": [],
  "author": "Marc Rasmussen",
  "license": "MIT",
  "devDependencies": {
    "@types/jest": "25.2.2",
    "chai": "^4.2.0",
    "es6-promise": "^4.2.8",
    "isomorphic-fetch": "^2.2.1",
    "jest": "25.2.2",
    "prettier": "^2.1.1",
    "ts-jest": "^26.3.0",
    "tslint": "^6.1.3",
    "tslint-config-prettier": "^1.18.0",
    "typescript": "^3.9.7"
  },
  "files": [
    "lib/**/*"
  ]
}

Once published on my private proget server, I integrate it into another project:

https://i.stack.imgur.com/G9oLP.png

In the importing project, the index.js configuration appears as follows:

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
var ContentIOService_1 = __importDefault(require("./IOServices/ContentIOService"));
module.exports = {
    ContentIOService: ContentIOService_1.default,
};

To utilize it in my TypeScript code, I include it like so:

import {LitElement, html, customElement, property} from 'lit-element';
import {ContentIOService} from 'sdk-io-package';
@customElement('my-test-element')
export class MyTestElement extends LitElement {

    @property()
    text: string = "Hello world";

    render() {
        this.test();
        return html`
        ${this.text} 
    `;
    }

  async  test (){
        const instance = ContentIOService.getInstance();
        const data = instance.GetContent("https://httpbin.org/get")
        console.log(data);
    }
}

declare global {
    interface HTMLElementTagNameMap {
        'my-test-element': MyTestElement;
    }
}

Upon running the application and serving it (successfully building with no TypeScript errors), accessing it through the browser yields this error message:

https://i.stack.imgur.com/WuDup.png

Uncaught (in promise) SyntaxError: The requested module '../../node_modules/sdk-io-package/lib/index.js' does not provide an export named 'ContentIOService'

Confusion sets in as I am unsure of where I went wrong.

A brief update:

Browsing through the node_modules folder in the browser reveals that the lib folders are absent along with the specific module:

https://i.stack.imgur.com/NLuZF.png

Answer №1

export = {
    DataIOService: DataIOService,
}

This isn't actually exporting a value called DataIOService. Rather, it is the default export of an object that contains a property named DataIOService. These two scenarios are not interchangeable.

To export a named value, you would typically do something like this:

import _DataIOService from "./IOServices/DataIOService";

export const DataIOService = _DataIOService;

You can also simplify this using a re-export:

export { default as DataIOService } from "./IOServices/DataIOService";

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

Reasons for dividing by 1 in JavaScript

While completing a basic programming assignment from my teacher, I encountered an interesting issue in Javascript. I found that when dividing a number by 1, it returns an unexpected value. Can anyone provide an explanation for this? I have created a jsfidd ...

Navigating with Angular/Routing through Dynamic Content

Exploring the best approach for managing dynamic content within an angular application has been my recent focus. Currently, I have an array containing phone numbers and aim to organize them based on their respective countries. For instance, all German phon ...

Does the AngularJS Controller disappear when the DOM element is "deleted"?

One challenge I encountered is regarding a directive that is connected to an angularjs controller, as shown below: <my-directive id="my-unique-directive" ng-controller="MyController"></my-directive> In the controller, at a certain point, I ne ...

The art of neatly bundling a Typescript external module at the highest level

I'm currently working on a TypeScript NPM package, where I have organized all the classes and interfaces. However, upon review, it seems that my approach is repetitive and not very clean, especially with the empty class and interface extensions. I am ...

React: Modifying a single input field out of many

Can someone please review this code snippet: https://stackblitz.com/edit/react-koqfzp?file=src/Section.js Whenever I add an item, a random number is also added that I want to be able to edit. This number is displayed in a Material UI Text Field component. ...

Arranging pre-selected checkboxes in MUI Datatable

I noticed that the checked data is appearing at the top of MUI data tables without any sorting. Checkbox In this image you can see that all the checked boxes are mixed up without any order. I would like to have all the checked rows displayed together and ...

Function that wraps JSX elements with the ability to infer types through generics

At the moment, this function is functioning properly function wrapElement(elem: JSX.Element) { return ({ ...props }) => React.cloneElement(elem, { ...props }) } I've been using it in this way to benefit from intelliSense for tailwind classes con ...

What are the typical situations in which Node.js is commonly used?

Do you believe that a majority of node.js users primarily utilize npm? What do you think are the most prevalent use cases for node.js apart from npm? ...

What is the preferred method for transferring server-side data to JavaScript: Using Scriplets or making an AJAX call?

At the server side, there is a property file that contains a list of words separated by commas. words.for.js=some,comma,separated,words The goal is to convert these words into a JavaScript array. var words = [some,comma,separated,words]; There are two ...

Protractor experiencing timeout issues while trying to launch Chrome Driver on Centos machine

Trying to run the angular-phonecat tutorial on a Centos 6.5 machine with Chrome version 33.0.1750.146, npm 1.4.3, and node version v0.10.31. Attempting to execute protractor tests: npm run protractor Encountering the following error, seeking guidance for ...

Ensure that the assistant stays beneath the cursor while moving it

I am currently working on creating a functionality similar to the 'Sortable Widget', but due to some constraints, I cannot use the premade widget. Instead, I am trying to replicate its features using draggable and droppable elements: $(".Element ...

Automatically arrange TypeScript import statements in alphabetical order in WebStorm / PhpStorm

I am using tslint with the default config tslint:recommended and I am looking to minimize the number of rules I need to customize. Some rules require that imports be alphabetized: src/core/task/TaskMockDecorator.ts[2, 1]: Imports within a group must be a ...

The perplexing simplicity of closure

Currently, I am endeavoring to enhance my knowledge of JavaScript closures. Let's consider the following two scenarios in Node.js: function A(){ console.log(data); //this will result in a null pointer } module.exports = function(data){ re ...

Tips for setting variable values in Angular 7

I'm encountering an issue with assigning values to variables in my code. Can anyone provide assistance in finding a solution? Here is the snippet of my code: app.component.ts: public power:any; public ice:any; public cake:any; changeValue(prop, ...

Having trouble resolving errors in Visual Studio Code after failing to properly close a parent function? Learn how to fix this issue

Here we have the code starting with the construct function followed by the parents function public construct() //child { super.construct; } protected construct() //parent { } The issue arises where I am not receiving an er ...

Verify that the select field has been chosen using Protractor

Currently, I am in the process of developing a test that places importance on whether a select field has already been populated. it('should automatically select a field if it hasn't been selected previously', function() { var usersField = ...

How to generate a new array in Angular by combining elements from two existing arrays for common items

I am currently working on a TypeScript function to compare two arrays and generate a third array containing the common items. For example: employees: any; offices: any; constructor() { this.employees = [ { fname: "John", lname: "James", sta ...

react-scripts: command missing within the React application

While running my react-app on localhost, an unexpected error occurred. Even though I have installed all the necessary dependencies using npm install, it seems to be unable to locate the react-scripts command for some unknown reason. ...

Compiling TypeScript to JavaScript with Deno

Currently experimenting with Deno projects and looking for a way to transpile TypeScript into JavaScript to execute in the browser (given that TS is not supported directly). In my previous experience with NodeJS, I relied on installing the tsc compiler via ...

JavaScript can be utilized to alter the style of a cursor

I'm currently developing a browser game and incorporating custom cursors into it. To ensure the custom cursor is displayed throughout the entire page, I've applied it in my CSS (though setting it up for 'body' occasionally reverts back ...