Rich-Harris / magic-string

Manipulate strings like a wizard
MIT License
2.37k stars 113 forks source link

type is wrong `This expression is not constructable` #251

Closed loynoir closed 1 year ago

loynoir commented 1 year ago

https://github.com/microsoft/TypeScript/issues/54166

just a quick fix

$ ln -rsf node_modules/magic-string/index.d.{ts,mts}
diff --git a/node_modules/magic-string/package.json b/node_modules/magic-string/package.json
index 42c2a99..3842bfe 100644
--- a/node_modules/magic-string/package.json
+++ b/node_modules/magic-string/package.json
@@ -19,7 +19,7 @@
   "exports": {
     "./package.json": "./package.json",
     ".": {
-      "types": "./index.d.ts",
+      "types": "./index.d.mts",
       "import": "./dist/magic-string.es.mjs",
       "require": "./dist/magic-string.cjs.js"
     }
freddy38510 commented 1 year ago

@loynoir Did you try to replace the line export default class MagicString { by export = class MagicString { ?

With commonjs, the current behavior maps the MagicString class to module.exports.default. Using export = instead of export default will map the MagicString class to module.exports.

You'll find a more detailed explanation of the export = syntax here.