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

Wait for the playwright to detect a specific and exact change in the inner text

There is a specific innerText that transitions from Loading to Play after 2-3 seconds. I want to wait for this change to happen before proceeding. Currently, I am using the following code snippet: let attempt = 0; let maxRetries = 4; let payerButtonStatus ...

Ways to determine the number of duplicate items in an Array

I have an array of objects that contain part numbers, brand names, and supplier names. I need to find a concise and efficient way to determine the count of duplicate objects in the array. [ { partNum: 'ACDC1007', brandName: 'Electric&apo ...

The variable 'React' is defined but not utilized in the code

Here's the code snippet in question: // tslint:disable import * as React from 'react'; import { Input, InputProps } from '../atoms/Input/Input'; import { FormControl } from '../hoc/FormControl/FormControl'; export const ...

Crafting your personalized npm starter-kit: A step-by-step guide

Cutting-edge technology: Innovative node.js frameworks provide users with starter-kits that serve as project blueprints, like React's ready-to-use kit. When a user wishes to initiate a new react application, they can utilize the shortcut npx create-r ...

Tips on displaying each element of an array in a unique format within a React component

I am working on creating a component that will display data in boxes. Each set of constant data should be placed within a div for organization. Currently, I have a Box component that is responsible for displaying the data. The Tutorial component receives ...

Make a div with absolute positioning overflow outside of a div with relative positioning that is scrollable

I am facing an issue with two columns positioned side by side. The right column contains a tooltip that overflows to the left on hover. Both columns are scrollable and relatively positioned to allow the tooltip to follow the scroll. However, the tooltip is ...

Toggle the visibility of a div based on the id found in JSON data

I am looking to implement a JavaScript snippet in my code that will show or hide a div based on the category ID returned by my JSON data. <div id="community-members-member-content-categories-container"> <div class="commun ...

Load page content dynamically with Ajax in a specific div while still allowing the option to open the content in a new tab by right-clicking

As I work on developing a new website that utilizes a MySQL database to sort various items into categories and subcategories, I have implemented a script that dynamically loads category content into a div without requiring a page reload. This seamless load ...

Looking to showcase an uploaded image next to the upload button in Vue.js using Element.ui?

I am currently working on implementing a feature that allows users to preview an image after uploading it. My approach involves uploading the image and then making an axios/AJAX call. Please see the following code snippet for reference: HTML code: ...

JavaScript: The delayed submission feature is malfunctioning

Visit this link When using JSFiddle, a strange list of errors is generated (see pic here). However, the auto-submit feature on my page works fine, but it lacks the specified delay. Thank you in advance for any assistance. <form id='formBlokUziv&a ...

Tips for implementing and utilizing onclick functions in EJS

My goal is to develop a trivia game with interactive features. I aim to enable users to click on an answer, which will trigger a border effect and increase the points variable. Below is the layout of the entire page: <% include ../partials/boilerp ...

Issue: The DLL initialization routine failed for electron, but it works perfectly fine on node.js

Currently, I am facing an issue while attempting to load a custom module in electron that is written in D using the node_dlang package. The module loads successfully with node, but encounters failures within electron. The test run with node, which works w ...

Restarting the timer in JavaScript

How can I reset the countdown timer every time a user types into an input field? I tried using clearTimeout but it doesn't seem to work. Can anyone help me with my existing code instead of providing new code? DEMO: http://jsfiddle.net/qySNq/ Html: ...

Retrieving a PHP variable from HTML without using a form

Is there a way to pass a variable from HTML to PHP without using a form and the traditional post or get methods? I have tried using the code provided, but I am unable to access the value of the 'buy1' variable in PHP. Is there a way to achieve th ...

Parsing a Jackson object in JavaScript that includes JsonIdentityInfo

Hey there (excuse my English) I've been working on an AngularJS front-end website that consumes a web service which produces JSON with Spring MVC. The Spring MVC uses the JsonIdentityInfo option for serialization, so each object is only written once ...

Having difficulty in deciding due to a response received from an ajax request

Currently, I am making an ajax request using jQuery to check the availability of a username in a database. The response from my PHP script is being successfully displayed inside a div with the ID "wnguser." However, I am facing issues when trying to use th ...

What is the best way to modify directives in response to updates in services?

In my directive (parent-directive), I have a slider called mySlider. When the slider is stopped, it triggers an event that calls an Angular $resource service with two parameters. The service then returns an object. The structure of the directives is as fo ...

Troubleshooting: Issues with jQuery.on method functionality

I'm currently using jQuery version 1.9.1 and I have a situation where I need to perform an action on a dynamically added td element. I attempted to utilize the jQuery.on function, however my code is not being triggered. Can someone please provide some ...

Tips on duplicating an object within a React state without using references

In my React application, I have a state that contains several objects. I need to make a copy of the c: "value" field from the initial state before it gets replaced by the input value from e.target.value. The purpose behind this is to ensure that ...

The recent update from Angular version 5.2 to 7 has caused issues with Post methods

An issue has occurred with the type mismatch in the error handling function. It seems that the argument provided is not compatible with the expected parameter type within the Observable structure. GetFullAddress(addressModel: FullAddr ...