Skip to content
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

Type error when importing docx in CJS file with TypeScript moduleResolution set to node16 #2846

Closed
danewilson opened this issue Nov 19, 2024 · 1 comment · Fixed by #2883
Closed

Comments

@danewilson
Copy link

Attempting to import anything from docx when using CommonJS using TypeScript when moduleResolution is node16 results in a type error like:

TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'.

This is because you haven't specified a CJS type declaration file. This tool explains the issue well, and also the solution.

@dolanmiu
Copy link
Owner

dolanmiu commented Nov 21, 2024

Isn't it specified here?

https://github.com/dolanmiu/docx/blob/master/package.json#L8

Edit: Ok, understood, this was helpful: https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/FalseESM.md

dolanmiu added a commit that referenced this issue Dec 5, 2024
dolanmiu added a commit that referenced this issue Dec 6, 2024
#2883)

* #2846 Type error when importing docx in CJS file with TypeScript moduleResolution set to node16

* Adhere to publint
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants