open-xml-templating/docxtemplater

HTMLModule Dependencies causing errors

Closed this issue · 1 comments

EA12 commented

Environment

  • Version of docxtemplater : 3.42.7
  • Used docxtemplater-modules : html-module-3.43.2
  • Runner : Node.JS 18.18.0 :: SPFx-Project with React 18.2.46

How to reproduce my problem :

Create a new SPFx-Project with React
Install Docxtemplater and the licensed HTML-Module
run gulp build (which is working fine)
run gulp bundle --ship (fails)

From my package-lock.json, i see following dependencies for the HTML-Module:

"dependencies": { "@adobe/css-tools": "^4.3.2", "color-js": "^1.0.5", "css-what": "^6.1.0", "docxtemplater": "^3.43.1", "domhandler": "^5.0.3", "he": "^1.2.0", "htmlparser2": "^9.1.0", "image-size": "^1.1.1", "lodash": "^4.17.21", "specificity": "^1.0.0" }

When i run gulp bundle --ship, i get following errors:

[17:44:14] Finished subtask 'webpack' after 4.77 s
[17:44:14] Finished 'bundle' after 8.35 s
[17:44:15] ==================[ Finished ]==================
Error - [webpack] 'dist':
./node_modules/htmlparser2/lib/esm/index.js 60:9
Module parse failed: Unexpected token (60:9)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| * They should probably be removed eventually.
| */

export * as ElementType from "domelementtype";
| import { getFeed } from "domutils";
| export { getFeed } from "domutils";
@ ./node_modules/docxtemplater-html-module/js/html-transformer.js 17:16-38
@ ./node_modules/docxtemplater-html-module/js/index.js
@ ./lib/extensions/createPdf/CreatePdfCommandSet.js
./node_modules/specificity/node_modules/css-tree/lib/index.js 8:9
Module parse failed: Unexpected token (8:9)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| export { Lexer } from './lexer/Lexer.js';
| export { tokenTypes, tokenNames, TokenStream } from './tokenizer/index.js';
export * as definitionSyntax from './definition-syntax/index.js';
| export { clone } from './utils/clone.js';
| export * from './utils/names.js';
@ ./node_modules/specificity/dist/esm/calculate.js 21:0-49 137:24-37 137:38-43 147:14-27 147:28-33 153:14-27 153:28-33
@ ./node_modules/specificity/dist/esm/index.js
@ ./node_modules/docxtemplater-html-module/js/css-parse.js
@ ./node_modules/docxtemplater-html-module/js/index.js
@ ./lib/extensions/createPdf/CreatePdfCommandSet.js
./node_modules/@adobe/css-tools/dist/index.mjs 98:23
Module parse failed: Unexpected token (98:23)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| line: lineno,
| column: column
}, options?.source || "");
| whitespace();
| return node;
@ ./node_modules/docxtemplater-html-module/js/css-parse.js 9:15-42
@ ./node_modules/docxtemplater-html-module/js/index.js
@ ./lib/extensions/createPdf/CreatePdfCommandSet.js

Is it correct that i would need a loader and add a webpack config to support the dependencies?

With the following js file :

const HTMLModule = require("docxtemplater-html-module");
const zip = new JSZip(template);                            
const options: Docxtemplater.DXT.Options = {
  linebreaks: true
};

const docxt = new Docxtemplater(zip, {
  // eslint-disable-next-line
  modules: [new (HTMLModule as any)({})]
});              

docxt.setOptions(options);
const data = {
    "SBReqProfile": { html: Html_Anforderungsprofil },
    "SBAddAreasOfResp": { html: Html_ErgaenzendeAufgabenbereiche },
    "SBTaskDescr": { html: Html_Aufgabenbeschreibung },
    "SBEmplMng": { html: Html_Mitarbeiterfuehrung },
    "SBFKMA": FKMA,
    "SBRunningNo": FortlaufendeNummer,
    "SBLayer": EbeneVerguetungsmodell,
    "SBJobFamily": JobFamily,
    "SBJobFamilyShort": JobFamilyAbkuerzung,
    "SBTitle": org_Title         
  };

  docxt.setData(data);

  docxt.render();              
  const output = docxt.getZip().generate({ type: 'nodebuffer' });

I would expect it to :

  • I can bundle my project without any loader-errors.

Hello @EA12 ,

I just tested this and it worked well for me.

I saw your email as well so I'm going to reply there to send you the correct code.

Edgar