-
Notifications
You must be signed in to change notification settings - Fork 5.1k
TypeScript type definitions don't work in NodeJS #2486
Comments
Have you tried |
That would work in plain old ES6, but because of the misastched TypeScript type definitions, the TypeScript compiler complains with a type error in the form of
|
One solution would be to have the TypeScript type definitions export both in the ES6 style and in the commonjs style but as far as I can tell that's not possible. |
Hey thanks for raising this, I will try to recreate your issue tomorrow and take a look. You are just trying to use the types in a standard node app? can you paste how your trying to import it please? that would be awesome. |
I think I know what it is - please still supply the above so I can confirm (I only really need the import your trying to do). I can then reply tomorrow once I’m online as I’m UK time and it’s 1am here at the moment. Thanks 👍 |
I've uploaded a test package here. Originally I was trying to use web3@^1.0.0-beta.38 from TypeScript in tests. |
Hey @yaram so your issue is due to the mismatch between how commonjs export stuff To fix this it you just have to enable
This then will allow you to import as you would anywhere like:
If you look at the compiled source now it does:
The Will add these instructions to the README so its clear how to get the typing's to work in a commonjs module. Thanks |
Description
The TypeScript type definitions do not work when used as a dependency in NodeJS. In the *.cjs.js files used by NodeJS, the old commonjs
exports =
form is used to export the modules, whereas in the TypeScript bindings the exports are defined to use the ES6export default
form, mapping toexports.default =
in the *.esm.js files.This issue is closely related to #1248.
Error Logs
Versions
The text was updated successfully, but these errors were encountered: