-
-
Notifications
You must be signed in to change notification settings - Fork 462
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
docx 7: does not work example of basic usage when using ES modules format in Node.js #1201
Comments
Try |
problem remains on version 7.1.0 |
on v 7.1.1 error: import { Document, Packer, Paragraph, TextRun } from 'docx'; import pkg from 'docx'; |
Strange I will investigate later |
Using Docx v7.1.1 I run code from Example of basic usage on nodejs in VS code without frameworks:
and catch the error:
package.json
it looks like somewhere in the source code Docx.js starting from version 7.0.0 mixed up ES6 modules (import, export) with CommonJS (require/module.exports). |
can you reproduce it on CodePen or StackBlitz? I can't seem to find the problem for me |
Type in Terminal (catch error on 2):
|
How does it work in v6, do you know? Does this mean v6 is both commonjs and esm? |
I have been researching, and it all points to this: https://www.sensedeep.com/blog/posts/2021/how-to-create-single-source-npm-module.html I wasn't doing any Hybrid magic before, so I am unsure why it needs to be done now? |
there was no such problem on version 6.0.3 |
maybe the problem arose because of the move from Webpack 3 to Webpack 5 |
maybe yes, maybe Webpack 3 did a hybrid but Webpack 5 dropped it? When I get time, ill turn it hybrid commonJS and ESM If you want to pick up this task, you could create a PR too |
@dolanmiu any progress in that? Sorry, I'm not skilled enough to try to solve it on my own |
@smolendawid I'm not too well versed in webpack either actually, i am using out of the box content |
Wanted to updated to 7.2, but I am facing this issue too |
Getting the same error with 7.3.0 after pasting and trying to run "Basic Usage" import { Document, Packer, Paragraph, TextRun } from "docx" import pkg from 'docx';
|
Can you do this?
I am on My theory is that there is ambiguity between the DOM |
You can import like this: import docx from "docx";
const {Document, Packer, Paragraph, TextRun} = docx; |
@dolanmiu, ESM and CommonJS works if build with changed webpack.config.ts: ... const configuration = { output: { ... |
But would this work as an iife? Like a standard |
Need to test |
Does not work |
Ah I see. Yes, this would be a requirement |
As variant to build 2 entry points: changes in a webpack.config.ts: const configuration = { output: { Who need docx.js in node.js through the ESM: import { The only thing I don't know is how to automatically duplicate index.d.ts with the name node.d.ts for types. |
Version 8.0.4 and Basic usage example still doesn't work in Node with ESM. Is it possible to at least update a documentation accordingly? |
Doesn't work for me with Angular. Neither the old way, nor the above suggestions:
|
Example of Basic Usage does not work on docx v7 (works on v6.0.3)
import { Document, Packer, Paragraph, TextRun } from 'docx';
^^^^^^
SyntaxError: Named export 'Packer' not found. The requested module 'docx' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:
import pkg from 'docx';
const { Document, Packer, Paragraph, TextRun } = pkg;
The text was updated successfully, but these errors were encountered: