-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
importing a class from a CJS package inside ESM package complains "not constructable" #47332
Comments
You wanna say I'm gunna look into seeing if we can issue a better error here that can help indicate what the correct solution is. |
Despite the type error, I'm able to import it's
How can we fix the type declaration to ensure it works in both ESM and CJS environment? |
Does |
(Alternatively, the types may just be wrong in saying that it's a default export, and a |
Sadly TypeScript is unable to export types along with a
Maybe this (export types along with |
"use strict";
const plugin = require('./');
module.exports = plugin.default; It shouldn't declare a default at all - just an |
You just move the other types-to-be-exported into the namespace associated with the class Plugin {
// ...
}
export = Plugin;
namespace Plugin {
export interface Whatever {} // like this
} |
Per [this issue](microsoft/TypeScript#47332) over on the TS repo, the current shape described by the types does not accurately describe the runtime shape of the entrypoint.
For other entrypoints, an export map would probably be appropriate. The current structure causes issues like microsoft/TypeScript#47332 where TS users can't actually accurately check the package.
The package in question actually already contains a definition for their cjs entrypoint, but their |
This issue has been marked as 'External' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
Hi, thanks to this response I was able to fix a problem with an old CJS module that I traied to use in a ESM Typscript project. I wondering where is the documentation about class exports with CJS to ESM compatibility. |
I'm having the same problem: since I moved to {
"compilerOptions": {
"moduleResolution": "NodeNext",
"module": "NodeNext",
"target": "esnext",
"lib": ["dom", "dom.iterable", "esnext", "WebWorker"],
"allowJs": true,
"allowImportingTsExtensions": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"noImplicitAny": false,
"noUnusedLocals": false,
"esModuleInterop": true,
"resolveJsonModule": true,
"strictPropertyInitialization": false,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"baseUrl": "."
}
} Is there any workaround? |
Bug Report
π Search Terms
class, not constructable, has no construct signatures
π Version & Regression Information
nodenext
moduleβ― Playground Link
Playground link with relevant code
Change
Module
configuration toNodeNext
to reproduce errors.π» Code
π Actual behavior
This simple code inside a
"type": "module"
package withtsconfig.json
declaraing"module": "nodenext", "moduleResolution": "nodenext"
can result in type errors:π Expected behavior
Since TypeScript already resolves type definition to correct
.d.ts
, and this type definition seems correct:This code should compile as expected.
The text was updated successfully, but these errors were encountered: