The imported package is not functioning properly within the project

I've recently developed a Typescript Package and I want to test it in an application before publishing it on NPM.

The main file (index.ts) of the package is structured like this =>

import Builder from './core/builder';

export default Builder;

Essentially, there are multiple files within the package, but I aim for the user to utilize a "static" class Builder that I export in the index. Therefore, the user can simply import it as import Builder from 'builderts'

The structure of my package.json looks like this:

  "name": "builderts",
  "main": "./dist/builderts.js",
  "types": "./dist/builderts.d.ts",
  "files": [
    "dist/*"
  ],
  "scripts": {
    "preversion" : "npm run lint",
    "prepare": "npm run build",
    "prepublishOnly": "npm test && npm run lint",
    "version" : "npm run format && git add -A src",
    "postversion" : "git push && git push --tags",
    "build": "tsc",
    "watch": "tsc-watch",
    "format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"",
    "lint": "eslint tsconfig.json"
  },

As for my tsconfig.json

{
    "compilerOptions": {
      "target": "es6",                          
      "module": "amd",                         
      "declaration": true,                      
      "declarationMap": true,                   
      "sourceMap": true,                        
      "outFile":"./dist/builderts.js",              
      "outDir": "dist",                         
      "strict": true,                           
      "esModuleInterop": true,                  
      "forceConsistentCasingInFileNames": true  
    },
    "include": ["src"],
    "exclude": ["node_modules", "dist"]
}

The issue I'm encountering is when I tried to create a small testing project and installed the module using

npm install absolute/path

the installation was successful, but upon trying to import the package with

import Builder from 'builderts';

I realized I didn't have autocomplete, and received an error message stating

File 'D:/User/Local/gitRepo/builderts/dist/builderts.d.ts' is not a module.

I'm puzzled about what might be missing in the process.

Answer №1

It appears that there is a necessity to revise the types within the package.json file.

Based on your mention of the file name being index.ts, have you taken into account the need to update the package.json? :

{ 
...
"types": "./dist/index.ts",
...
}

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

The use of jQuery ajax requests is leading to a refresh of the page

I've encountered an issue with a button on my HTML page that is not associated with any form. <input type='button' id='submitter' value='add'/> There is a click handler attached to it: $('#submitter').c ...

Incorporate JSON information into a sleek Bootstrap modal interface

I am looking to load a JSON file to generate a list within a Bootstrap Modal. The setup I have allows for the modal to appear when clicking on a person's image. <li class="project span3" data-type="pfa"> <a data-toggle="modal" data-targe ...

Display or conceal image based on date

I'm interested in showing a unique zodiac sign image on my website according to the date of the year. For instance, from March 21st to April 21st, I want to display the "Aries" image; from April 22nd to May 21st, I want to show the "Taurus" image, and ...

Is it possible for Jaydata relationships to function seamlessly without the need to be

I am attempting to set up a basic model with Parent -> Child relationships (correctly declared and functioning, I believe). This is my approach: var parent = new $data.Types.Parent(); $data.context.Parents.add(parent); parent.Code = 123; var child = ...

What causes npm-shrinkwrap.json file to update during the npm install process?

We rely on NPM Shrinkwrap to firmly secure dependencies. Uncertain whether it's a glitch or an intended feature, whenever we delete the node_modules directory and run npm install again, minor alterations are made to our npm-shrinkwrap.json which need ...

Should we integrate a MongoDB database calculation app with a POST Controller in sails.js?

The primary function of the application interface is to provide variables that have been initially posted by the client, as well as any subsequent database calculations carried out in real time by a specialized engine. Is it possible to integrate this eng ...

Ways to retrieve a property that is dynamically generated within a React component

In the code snippet below, I have registered the TextField name as M1.${index}.M13-M14 and it is marked as required. However, I am unable to locate the property accessor using errors[`M1.${index}.M13-M14`]?.type, which prevents the error from being gener ...

Incorporate pictures from the popup onto the main page

I have developed a basic PHP image editor script where users can select images from galleries and merge them together. However, I am facing an issue: The galleries open in a popup while the editor area is on the parent page. I am looking for a JavaScript ...

The functionality of nested routing is not operating properly in react-router

I'm currently struggling to get my CollectionPage to render and match the URL correctly within my nested Route in React. Unfortunately, it doesn't seem to be working as expected! Here's a piece of code from my shop.component file that is be ...

Dealing with Ajax errors in Django reponses

My code includes an ajax call to a Django view method: $("#formi").submit(function(event){ event.preventDefault(); var data = new FormData($('form').get(0)); $.ajax({ type:"POST", url ...

Is there a method to make changes to files on a deployed Angular application without the need to rebuild?

After deploying my Angular application on a production environment using the command npm run build --prod --base -href, I now need to make changes to some static HTML and TypeScript files. However, since the app is already bundled and deployed, I'm un ...

Avoiding the ESLint error of missing return type in a React TypeScript function

My JavaScript function looks like this: export default () => ({ root: css` background-color: hotpink; margin-bottom: 1.45rem; `, }); However, ESLint is raising a complaint: Missing return type on function.eslint@typescript-eslint/explicit-m ...

Installation of npm failed due to error codes E404 or ENOENT

My current node version is 8.9.1; NPM version I am using is 5.5.1; Whenever I attempt to install modules using NPM, I encounter errors such as 'code E404' or 'code ENOENT'; I have tried installing various modules, including 'tld ...

Using TypeScript TSX with type parameters

Is it possible to define type parameters in TypeScript TSX syntax? For instance, if I have a class Table<T>, can I use something like <Table<Person> data={...} /> ...

From navigating getElementByID to tackling getElementsByClassName while constructing multiple select elements: a guide

I am facing an issue with accessing multiple select elements that have the same options in Javascript. Despite having the same class, I am unable to retrieve the options using Javascript. When I attempted switching from getElementById to getElementsByClass ...

Is there any method to determine whether a floated element has been pushed down?

Imagine a dynamic menu with floating elements, each set at a width of 150px. As the menu's width decreases, the elements progressively move to the next row. You are contemplating how to detect when an element has been moved down. One approach could b ...

Trouble arises when attempting to create a two-column layout using Material UI's <Grid> component

My goal is to create a two-column layout where each column takes up half of the screen and has equal height. To better illustrate, take a look at this image. The code I've tried so far is not working as expected: import React from "react"; import { ...

Determining the moment a user exits a page on Next JS

Is there a way to track when the user exits a Next JS page? I have identified 3 possible ways in which a user might leave a page: Clicking on a link Performing an action that triggers router.back, router.push, etc... Closing the tab (i.e. when beforeunloa ...

Finding it challenging to adapt an AngularJs component-based modal to TypeScript

When creating an AngularJS component in JavaScript and displaying it as a modal using ui-bootstrap, you need to pass bindings that the modal instance can use for dismissing or closing itself: app.component("fringeEdit", { controller: "FringeEditCont ...

ReactJS not updating when multiple checkboxes are selected

Struggling to resolve an issue with this component. I encounter an error when trying to select multiple items using checkboxes. Oddly enough, another one of my components with the same code has no error. Please take a look at my code below, any help is gre ...