Having trouble locating a locally linked module in Typescript?

Currently, I am in the process of testing some TypeScript definitions that I created for a Node project that lacks them. These definitions are functioning properly when included in my project that utilizes the target Node project as well as when placed in my own folder within node_modules/@types/ (

node_modules/@types/chrome-aws-lambda/index.d.ts
). The setup involves Node 8.10, npm 5.6, and TypeScript 3.1.

Despite this, I have forked the module's repository from GitHub with the intention of incorporating it into the project for wider usage. To achieve this, I modified the package.json file of the forked project to direct types to

source/index.d.ts</code which is located alongside the <code>main
file,
source/index.js</code. Subsequently, I linked it in my project using <code>npm link ../chrome-aws-lambda
.

Unfortunately, this approach is not successful. When running tsc, an error is returned stating:

error TS2307: Cannot find module 'chrome-aws-lambda'
When executed with --traceResolution, it seems like the module is not being sought after at all.

I suspect that the issue may be related to the package not truly being 'installed'. Attempting to manually copy the project directory into the node_modules instead of linking it did not resolve the problem. I also considered that TypeScript might not be recognizing the types field in the package.json, so I added one in the root since that is the default behavior. Additionally, I verified if it was being included by adding it to the include section of my .tsconfig. Further adjustments were made to baseUrl, paths, typeRoots, and moduleResolution in the configuration file without success.

All these efforts have been futile.

Prior to submitting a PR, I need confirmation whether the solution is effective or not. Any guidance on how to proceed would be greatly appreciated. If additional information is required, please do not hesitate to request! Below, you will find the index.d.ts along with the import statement provided, just in case there is an oversight in that area.

Thank you!

index.d.ts:

declare module 'chrome-aws-lambda' {
    import * as Puppeteer from 'puppeteer';

    export default class Chromium {
        static args : Array<string>;
        static defaultViewport : {
            width : number,
            height : number,
            deviceScaleFactor : number,
            isMobile : boolean,
            hasTouch : boolean,
            isLandscape : boolean
        };
        static executablePath : Promise<string>;
        static headless : boolean;
        static puppeteer : typeof Puppeteer;
    }
}

Furthermore, here is the import statement in question:

import Chromium from 'chrome-aws-lambda';

Answer №1

As mentioned in this response, the key is to convert your .d.ts file into a module structure. Hopefully, this tip proves helpful.

Additionally, there's no need to place your .d.ts file in a specific location within your project; it can reside anywhere. For further insights, check out this conversation.

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

Utilizing Google OAuth2 API within an Angular2 Typescript Application

Looking to incorporate the Google oauth2 API and Calender API into my Angular2 application. Struggling to find a working sample to guide me through the integration process. Has anyone come across a functioning example? Thanks, Hacki ...

Gradle encountered an issue while trying to run the npm command

I've encountered a strange error while attempting to execute an npm command within a gradle task: Caused by: net.rubygrapefruit.platform.NativeException: Could not start 'npm' at net.rubygrapefruit.platform.internal.DefaultProcessLaunch ...

Merging Type-GraphQL and Typegoose through a Variety of Decorators

Using a combination of Type-GraphQl and Typegoose, I aim to streamline my data definitions by consolidating them into one source for both GraphQL schemas and Mongoose queries. Is it feasible to merge the two libraries in a way that allows me to describe bo ...

Issue with loading dynamic components in Angular 2

I am facing a strange issue with dynamic component loading in Angular. I have set up a form stepper with 5 steps, each step being a separate component that is injected when necessary. class CreateComponent { // List of components to be injected pri ...

What steps are needed to configure ESLint to exclusively analyze .ts files?

I need ESLint to exclusively focus on processing .ts files and not .js files. In order to achieve that, I made a .eslintignore file and included the following lines: *.js **/*.js Nevertheless, it appears that ESLint is disregarding this file. Is there so ...

Determine the point where a cube intersects a plane using Three.js

Given a plane and a cube, I am interested in determining if they intersect. If they do intersect, I would also like to find out: What shape does their intersection form - a triangle, a parallelogram or a hexagon? In degenerate cases, it may just be a p ...

Utilize lazy loading to trigger secondary API calls once all data from the initial API call has been fully loaded in React js

Looking for a way to display data from multiple .json files with lazy loading in the browser using React JS? The goal is to initially load and show all the data from the first .json file, and then make an API call to fetch data from the second .json file ...

How can I retrieve the total number of records (count) in an XML response using PostMan?

Hello, I'm currently attempting to determine the length of an XML response but I'm running into some issues. The error message I am encountering is as follows: "There was an error in evaluating the test script: ReferenceError: xml2json is not def ...

What is the best way to dynamically retrieve the locale from dayjs library?

Whenever I try using dayjs(date).locale('te').format('YYYY MMM DD'), the Month value is displayed in English. In order to work with locale, I need to import it. import * as locale from 'dayjs/locale/te'; The issue arises whe ...

Operating Laravel-Mix 8 while executing the watch command

How can I successfully load a Vue Component in the Public file using npm run watch? Node.js v14.15.0. npm 6.14.8 Laravel Installer 4.1.0 When running npm run watch in my project directory, I encountered the following error ...

Facing the Challenge: Overcoming Concurrency Issues with Promises

In the function "myMethod" within my "gulpfile.js", I aim to generate multiple Promises based on the size of an array passed as a parameter. It is crucial for all promises to be fulfilled before proceeding with any further actions upon calling this functio ...

Using TypeScript to Manipulate SVG Polyline Shapes

In my TypeScript 3.1.1 project in VS Code with an Aurelia setup, I am facing a challenge while trying to manipulate an SVG Polyline using TypeScript code. The issue arises when attempting to create a new SVGPoint object. The initial HTML structure is as fo ...

Verify the presence of npm package dependencies listed in package.json without requiring an internet connection

Is there a way for npm to inform me if all dependencies are already installed without requiring a network check? My objective is to initially verify locally if any dependencies need to be installed. If anything is missing, I will then execute a standard n ...

Leveraging ES6 Symbols in Typescript applications

Attempting to execute the following simple line of code: let INJECTION_KEY = Symbol.for('injection') However, I consistently encounter the error: Cannot find name 'Symbol'. Since I am new to TypeScript, I am unsure if there is somet ...

Unable to deploy a sails.js application on an Amazon EC2 or DigitalOcean Ubuntu server using forever or pm2

After installing sails.js (v0.9.16) globally on amazon-ec2 / digitalocean ubuntu, I created a test project and successfully lifted the server: sudo npm -g install sails sails new sailstest cd sailstest sails lift I was able to access the sails app home ...

Ensuring that an interface exclusively contains properties from another interface

If I define an interface like this: interface Client { id: number; email: string; firstName: string; lastName: string; cellNumberFull: string; } Then, how can I create a new interface that includes only the properties from GoClient? interface ...

Struggling to create an accurate regular expression for validating URLs

I am currently working on a project where I need to create rules to avoid accepting incorrect URLs. I have decided to use regex for this purpose. My URL format is "http://some/resource/location". This URL should not contain any spaces at the beginning, m ...

Transform the Standard class into a generic one in typescript

I've created a class that can take JSON objects and transform them into the desired class. Here's the code: import {plainToClass} from "class-transformer"; import UserDto from "../../auth/dto/user.dto"; class JsonConverter { ...

Using Typescript in conjunction with nodemon and VS Code for seamless integration of declaration merging

After adding a middleware to my express app app.use(function(req: express.Request, res: express.Response, next: express.NextFunction) { req.rawBody = 'hello2'; next(); }); I also included custom.d.ts declare namespace Express { expor ...

The command "cucumber.js" is not recognized or cannot be found

Following the steps in this tutorial: https://github.com/lykmapipo/nodejs-cucumber-sample The version displayed by nvm current is: v10.12.0. The version displayed by npm --version is: 6.4.1> Encountering an error when running npm test: > <a h ...