Having trouble importing a variable from a precompiled library in TypeScript JavaScript

Here is the content of my package.json file:

{
  "name": "deep-playground-prototype",
  "version": "2016.3.10",
  "description": "",
  "private": true,
  "scripts": {
    "clean": "rimraf dist",
    "start": "npm run serve-watch",

    "prep": "browserify src/csv.ts -p [tsify] | uglifyjs -c > csv.js && copyfiles analytics.js dist && concat node_modules/material-design-lite/material.min.js node_modules/seedrandom/seedrandom.min.js csv.js > dist/lib.js",
    "build-css": "copyfiles fonts.css dist && concat node_modules/material-design-lite/material.min.css styles.css > dist/bundle.css",
    "watch-css": "concat node_modules/material-design-lite/material.min.css styles.css -o dist/bundle.css",
    "build-html": "copyfiles index.html dist",
    "watch-html": "concat index.html -o dist/index.html",
    "watch-js": "watchify src/playground.ts -p [tsify] -v --debug -o dist/bundle.js",
    "build-js": "browserify src/playground.ts -p [tsify] | uglifyjs -c > dist/bundle.js",
    "build": "npm run prep && npm run build-js && npm run build-css && npm run build-html",
    "watch": "npm run prep && concurrently \"npm run watch-js\" \"npm run watch-css\" \"npm run watch-html\"",
    "serve": "http-server -o -c-1 dist/",
    "serve-watch": "concurrently \"http-server -o -c-1 dist/\" \"npm run watch\""
  },
  "devDependencies": {
    "@types/d3": "^3.5.41",
    "concat": "^1.0.3",
    "concurrently": "3.1.0",
    "copyfiles": "1.0.0",
    "http-server": "^0.11.1",
    "rimraf": "2.5.4",
    "tsify": "^4.0.0",
    "typescript": "^2.9",
    "uglify-js": "^2.8.29",
    "watchify": "^3.11.0"
  },
  "dependencies": {
    "@types/jquery": "^3.3.27",
    "csv-parse": "^4.2.0",
    "csvtojson": "^2.0.8",
    "d3": "^3.5.16",
    "https-proxy-agent": "^2.2.1",
    "material-design-lite": "^1.3.0",
    "seedrandom": "^2.4.3",
    "typings": "^2.1.1"
  }
}

The contents of the csv.ts file are as follows:

import {csv} from 'd3';
async function delay(ms: number) {
    return new Promise( resolve => setTimeout(resolve, ms) );
}
export let train = [];
(async()=>{console.log('before delay');csv("training.csv",function(error,data){train = data});await delay(1000);console.log('after delay')})();

I am attempting to load data into a variable called train initially. Then I am trying to import it from the lib.js file into the program:

import {train} from 'lib';

However, after compilation, I am encountering the following error:

TypeScript error: src/dataset.ts(17,21): Error TS2307: Cannot find module 'lib'.

It seems like I have missed a step in this process.

Answer №1

If you don't alter the way your module loading logic functions, chances are you will require a relative import path:

import { train } from './lib'; // Adjust path if not in the same folder

The use of 'lib' is suitable only if it is a known module, such as a dependency that has been installed to the node_modules directory.

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

Discover the process for breaking down JSON data into separate stages using the Express API

My API architecture is causing a problem as I try to insert it into an array called items[]. https://i.stack.imgur.com/qe802.png The setup involves a simple API built on express + mongodb. The challenge lies in figuring out how to store data from the pos ...

Utilizing AngularJS for manipulating a multidimensional array with interdependent select boxes

I have a unique collection of product names along with their respective versions stored in a multidimensional array. My goal is to design an interactive interface that allows users to first select a product from a drop-down menu and then choose the version ...

Divide the strings within an array

When working with nodejs, I utilize walksync to obtain an array as shown below: var paths = ['Essential Classes.jade' , 'introduction.jade'] These are the filenames contained within a folder. The objective is to extract only the filen ...

Even though I have successfully compiled on Heroku, I am still encountering the dreaded Application Error

Looking for help with a simple express/node application to test Heroku? Check out my app.js: const express = require('express') const app = express() const port = '8080' || process.env.PORT; app.get('/', function (req, res) ...

Tips for concealing content within table cells

I am facing an issue with my form that contains a table. When the user clicks on the radio button labeled "No", I want the content of the subsequent cells in that row to become visible. However, when they click on "Yes", the content should be hidden again. ...

Managing arrayBuffer in hapi.js: A Comprehensive Guide

I am struggling to upload an arrayBuffer to my server and save it to a file. On the client side, I am using axios, and on the server side, I have implemented Hapi js. However, I am facing difficulties in extracting data from the request in the Hapi handler ...

React checkbox displaying incorrect render

I'm currently working on developing a React component that acts as a tile representation. This particular component consists of a div containing a label and a checkbox. The issue I'm facing is that I can click anywhere on the component to trigg ...

Resolve character encoding issues in a JavaScript CSV HTTP response file

When I receive a CSV file as a response from an API, I encounter issues with special characters in French appearing distorted. The content in the CSV files looks like this: Exampleé of Weiéérdnesséé Is there a way to standardize these ...

Storing information from a table into LocalStorage

$('.new_customer').click(function () { var table = $("table"); var number = table.find('tr').length; table.append('<tr id="' + number + '"><td><input type="button" class="btn btn-success btn-xs" ...

Extract the necessary fields from the JSON Schema

I am in search of a solution to extract the required fields from a JSON Schema and Data combination. Currently, we are utilizing AJV for getting error messages in our forms using JSON Schema, and it has been performing really well. I am looking for a met ...

Discovering dependencies for the Tabulator library can be achieved by following these

Can anyone provide me with a complete list of dependencies for Tabulator 4.2? I have already reviewed the package.json file, but it only contains devDependencies. ...

Distinct elements within a JavaScript hash

Is there a jQuery method to add a hash into an array only if it is not already present? var someArray = [ {field_1 : "someValue_1", field_2 : "someValue_2"}, {field_1 : "someValue_3", field_2 : "someValue_4"}, {field_1 : "someValue ...

Having trouble getting CSS Animation to work in a React project?

I am currently developing a Next.js application using React. const partyButton = useRef(null) const handleParty = () => { setTimeout(() => { partyButton.current.classList.add('party-time'); console.log(party ...

Is there a way to modify an npm command script while it is running?

Within my package.json file, I currently have the following script: "scripts": { "test": "react-scripts test --watchAll=false" }, I am looking to modify this script command dynamically so it becomes: "test&qu ...

Leveraging React's state to enable temporary invalid numeric input handling

My current approach may be flawed, but I aim to have a parent component and a child component, where the child contains an input field for users to enter numbers. The callback function of the parent component will only be triggered for valid numbers, as ve ...

The element type provided is not valid: it should be a string for built-in components or a class/function for composite components. However, an object was received instead. - React Native

After conducting extensive research, I have been unable to find a solution as to why this issue persists. Can anyone shed some light on what the error might be referring to? Error: Element type is invalid: expected a string (for built-in components) or a c ...

Guide on retrieving JSON information within an array utilizing a loop function

Hey everyone, I'm facing an issue and I could really use some help. I'm new to working with ajax processing and I'm stuck on a problem. I have successfully retrieved ajax data and now I need to store it in an array. My goal is to populate a ...

Encountering an issue: Module not found - 'cryptile' during express js installation

Just dipping my toes into the world of Node.js and I'm encountering some obstacles when trying to install Express.js. Seeking assistance in resolving this issue and successfully setting up Express.js. https://i.stack.imgur.com/PlHiB.png Interestingl ...

My code gets disrupted when I switch between ids and classes

I'm currently learning about javascript and jquery, attempting to implement various scripts. I successfully executed the following script: jQuery(document).ready(function($) { var scroll_start = 0; var startchange = $('#homepage-header' ...

tap the hyperlink to complete the form and mimic the action of a designated

I'm working on an HTML form that includes a table and two submit buttons. <input type="image" name="button1" value="First Button" src="some_image.png"> <input type="image" name="button2" value="Second Button" src="some_image.png"> One ch ...