-
-
Notifications
You must be signed in to change notification settings - Fork 37
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
import * as stripAnsi from "strip-ansi"; #11
Comments
|
@kevva Thanks for your quick answer! Unfortunately, it doesn't work... |
Because CommonJS and modules works differently. It's like when you're requiring a module in CommonJS where you have to write: const module = require('module').default; |
I see. Is there any way that I can import this module using ES6 module syntax? Alternatively, changing the module to: module.exports = {
stripAnsi: function (str) {
return typeof str === 'string' ? str.replace(ansiRegex, '') : str;
}
}; allows to use (in TypeScript) import * as stripAnsi from 'strip-ansi'; as well as (in JavaScript) const stripAnsi = require('strip-ansi'); I'm not sure if this might cause any troubles in other packages. If not, I would create a pull request for this change if you're okay with it. |
We're not going to change just because you use TypeScript. If you use TypeScript it's up to you to figure out how to use packages with it. This module is exported exactly like most npm packages. |
I tried to import stripAnsi with
import * as stripAnsi from "strip-ansi";
in a TypeScript-Node.js application but this fails with the error messageModule '"/.../node_modules/@types/strip-ansi/index"' resolves to a non-module entity and cannot be imported using this construct.
. The issue seems to be that a function is exported (see e.g. microsoft/TypeScript#5867 (comment)). Would it be possible to change that to something consumable by TypeScript? Or is there any other way I might get this to work?I know that this module isn't doing much and that I can easily write such a function on my own but I thought maybe other people are going to have the same issue as well so maybe we can try to find a solution for it.
The text was updated successfully, but these errors were encountered: