Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chrome-launcher typescript compiler, can't find name #2497

Closed
pedro93 opened this issue Jun 13, 2017 · 9 comments · Fixed by #2513
Closed

Chrome-launcher typescript compiler, can't find name #2497

pedro93 opened this issue Jun 13, 2017 · 9 comments · Fixed by #2513
Assignees

Comments

@pedro93
Copy link

pedro93 commented Jun 13, 2017

After adding chrome-launcher as a module to the pwmetrics project I came across this typescript issue:

> [email protected] build /home/pedro.cardoso/dev/pwmetrics
> tsc

lib/index.ts(36,13): error TS2304: Cannot find name 'chromeLauncher'.
lib/index.ts(146,33): error TS2503: Cannot find namespace 'chromeLauncher'.

The respective code is:

const chromeLauncher = require('chrome-launcher');
....

 async launchChrome(): Promise<chromeLauncher.LaunchedChrome|Error> {
    try {
      console.log(messages.getMessage('LAUNCHING_CHROME'));
      this.launcher = await chromeLauncher.launch({
        port: this.flags.port,
        chromeFlags: this.flags.chromeFlags
      });
      this.flags.port = this.launcher.port;
    } catch(error) {
      await this.killLauncher();
      return error;
    }
  }

If I add the project as a js module (not in the docs I know) I get the following:

lib/index.ts(5,38): error TS7016: Could not find a declaration file for module 'chrome-launcher'. '/home/pedro.cardoso/dev/pwmetrics/node_modules/chrome-launcher/chrome-launcher.js' implicitly has an 'any' type.

I import the module as:

import {chromeLauncher, LaunchedChrome} from 'chrome-launcher';
....

async launchChrome(): Promise<LaunchedChrome|Error> {
    try {
      console.log(messages.getMessage('LAUNCHING_CHROME'));
      this.launcher = await chromeLauncher.launch({
        port: this.flags.port,
        chromeFlags: this.flags.chromeFlags
      });
      this.flags.port = this.launcher.port;
    } catch(error) {
      await this.killLauncher();
      return error;
    }
  }

System details:
Ubuntu 16.04 LTS
Node: V8.0.0
NPM: V5.0.0

How to reproduce:
Trying to merge LH.v2 to pwmetrics and add the chrome-launcher dependency :)

Thanks for the time.

@pedro93 pedro93 changed the title Chrome-launcher can't find name Chrome-launcher typescript compiler, can't find name Jun 13, 2017
@samccone samccone self-assigned this Jun 13, 2017
@samccone
Copy link
Contributor

samccone commented Jun 13, 2017

chromeLauncher is not exported from
https://github.com/GoogleChrome/lighthouse/blob/master/chrome-launcher/chrome-launcher.ts

for typescript consumption do the following

import {launch, LaunchedChrome} from 'chrome-launcher';

let launched: LaunchedChrome;
launched = await launch();

// or even simpler

import {launch} from 'chrome-launcher';

const launched = await launch();

@pedro93
Copy link
Author

pedro93 commented Jun 14, 2017

Thanks for looking into this @samccone, i've tried your suggestion but I still get the message:

lib/index.ts(5,22): error TS7016: Could not find a declaration file for module 'chrome-launcher'. '/home/pedro.cardoso/dev/pwmetrics/node_modules/chrome-launcher/chrome-launcher.js' implicitly has an 'any' type.

Here is the travis build: https://travis-ci.org/paulirish/pwmetrics/builds/242740991
and the relevant source code (its incapsulated in index.ts): https://github.com/paulirish/pwmetrics/pull/120/files#diff-13b5b151431c7e7a17f273559ed212d5

I noticed that chrome-launcher is exported as a standard javascript project, and that it doesn't have a explicit types files, could either of these be the cause of the problems? Or can I not use the chrome-launcher types in pwmetrics?

@denar90
Copy link
Contributor

denar90 commented Jun 14, 2017

import {launch, LaunchedChrome} from 'chrome-launcher/chrome-launcher'; - solving the problem

@pedro93
Copy link
Author

pedro93 commented Jun 14, 2017

Would renaming chrome-launcher.ts to index.ts and changing the package.json[main] property accordingly make this work? The nested import seems counter intuitive.

@samccone
Copy link
Contributor

I will investigate how we can better handle this.

@pedro93
Copy link
Author

pedro93 commented Jun 14, 2017

May I suggest trying to rename the chrome-launcher files to index and changing accordingly in the package.json?

@samccone
Copy link
Contributor

samccone commented Jun 14, 2017

The primary consumption point of this module is going to be javascript so we can not change that bit, however renaming to index.ts might end up fixing the problem as well. ~~ investigation needed ~~

@samccone
Copy link
Contributor

Going to close this issue as working as intended. we can follow up with investigation around easier typescript requires.

@paulirish
Copy link
Member

the #2513 fix is shipped in [email protected]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants