I'm trying to test some typescript definitions that I made for a node project that doesn't have any. They work already when I include them in my project that consumes the target node project, or when I make my own folder in node_modules/@types/
and put them there(node_modules/@types/chrome-aws-lambda/index.d.ts
). This is using node 8.10, npm 5.6 and typescript 3.1
However, I have forked the repository for the module from github and am hoping to include it in the project so others can use it. In order for this to happen, I have edited the forked project's package.json
to point types
to source/index.d.ts
that lives beside the main
, source/index.js
file. Then in my project I link it using npm link ../chrome-aws-lambda
.
This does not work. When I run tsc
it can not find the module it says.
error TS2307: Cannot find module 'chrome-aws-lambda'
When I run it with the --traceResolution
it doesn't even seem like it tries to look for it.
I've figured that it may have something to do with the package not being really 'installed' so I've tried to just copy the project directory into the node_modules
instead of linking it. I've also thought perhaps something wasn't working and typescript wasn't reading the types
field in the package.json
so I put one in the root as that's the default. I thought perhaps it wasn't being included and so I added it in the include part of my .tsconfig
. I've tried to change my baseUrl
, paths
, typeRoots
, and moduleResolution
in the config file as well.
None of this works.
I don't want to submit a PR without being able to know if it works or not. Does anyone have any clues as to what to do here? I'll gladly add any relevant information needed, please just let me know! I've included the index.d.ts
as well as the import statement below in case I'm just doing something stupid there.
Thanks!
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;
}
}
as well as the import statement in question:
import Chromium from 'chrome-aws-lambda';
According to this answer, you have to make your
.d.ts
file a module. Hope it will help.Also, you don't have to put
.d.ts
to special path, it can be in project at any place. I think this discussion will be very helpful.