question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't import from Typescript

See original GitHub issue

I’m trying to use chrome-promise in a Typescript Chrome Extension. The documented ES usage is:

import ChromePromise from 'chrome-promise';

const chromep = new ChromePromise();
chromep.something_or_other('param');

When I do the same in Typescript everything transpiles properly - ChromePromise is recognized with the right type information. Intellisense is shown, Typescript catches errors if I call a non-existing method - it’s all fine.

At runtime, however, I can’t create the ChromePromise instance. I get the following error:

Uncaught TypeError: chrome_promise_1.default is not a constructor
    at Object.__WEBPACK_AMD_DEFINE_ARRAY__ (background.js:77)
    at __webpack_require__ (background.js:20)
    at Object.defineProperty.value (background.js:63)
    at background.js:66

And indeed, chrome_promise_1.default is undefined, while chrome_promise_1 is a function.

Changing the import to import { ChromePromise } from ... results in an error saying ChromePromise is undefined.

import * as ChromePromise from ... yields an error saying ChromePromise has no type.

There’s also a Stack Overflow question: https://stackoverflow.com/questions/47651244/cant-import-from-chrome-promise-in-typescript

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:15 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
tfoxycommented, Dec 6, 2017

Hi! I think I used webpack when I tested typescript. Let me check tomorrow if I find anything. I will try @NaridaL solution first.

1reaction
NaridaLcommented, Dec 5, 2017

I saw your SO question. As far as I can see, the typings are wrong. They declare a default export but that isn’t reflected in the JS. The typings should have the form:

class ChromePromise {
}
export = ChromePromise // so require() works
export as namespace ChromePromise // so global is accessible

You would then use it as Import CP = require('chrome-promise'), or with syntheticDefaultExports: import CP from 'chrome-promise'.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't import TypeScript modules without providing the file ...
I am very new to TypeScript and I expect I should be able to import my TS files without needing to specify that...
Read more >
Common TypeScript module problems and how to solve them
Solution 2: Locate the module and resolve imports ; "*" value in the array means the exact name of the module, while the...
Read more >
Documentation - Module Resolution - TypeScript
Module resolution is the process the compiler uses to figure out what an import refers to. Consider an import statement like import {...
Read more >
Cannot import Typescript files from outside of 'dir' directory
Bug report When using a custom server, trying to import a .ts file from outside of the dir directory results in the following...
Read more >
How To Use Modules in TypeScript | DigitalOcean
Using export = and import = require() for Compatibility ... Some module loaders, like AMD and CommonJS, have an object called exports that ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found