Can't import from Typescript
See original GitHub issueI’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:
- Created 6 years ago
- Comments:15 (9 by maintainers)
Hi! I think I used webpack when I tested typescript. Let me check tomorrow if I find anything. I will try @NaridaL solution first.
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:
You would then use it as
Import CP = require('chrome-promise')
, or with syntheticDefaultExports:import CP from 'chrome-promise'
.