lindell / lindell/JsBarcode

README With svg demo: TypeError: document.createElement(...).getContext is not a function

Open
#428 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
5.9k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

I want to use JsBarcode in svg, so i found this in readme file.
i try this step by step, but got some errors
```
const { DOMImplementation, XMLSerializer } = require('xmldom');
const xmlSerializer = new XMLSerializer();
const document = new DOMImplementation().createDocument('http://www.w3.org/1999/xhtml', 'html', null);
const svgNode = document.createElementNS('http://www.w3.org/2000/svg', 'svg');

JsBarcode(svgNode, 'test', {
xmlDocument: document,
});
```
error:
```
Thrown:
TypeError: document.createElement(...).getContext is not a function
at messureText (/Users/longen/temp/node_modules/jsbarcode/bin/renderers/shared.js:77:42)
at calculateEncodingAttributes (/Users/longen/temp/node_modules/jsbarcode/bin/renderers/shared.js:39:16)
at SVGRenderer.prepareSVG (/Users/longen/temp/node_modules/jsbarcode/bin/renderers/svg.js:59:44)
at SVGRenderer.render (/Users/longen/temp/node_modules/jsbarcode/bin/renderers/svg.js:36:9)
at render (/Users/longen/temp/node_modules/jsbarcode/bin/JsBarcode.js:227:11)
at API.render (/Users/longen/temp/node_modules/jsbarcode/bin/JsBarcode.js:206:3)
at JsBarcode (/Users/longen/temp/node_modules/jsbarcode/bin/JsBarcode.js:76:55)
```

env:
node: v10.24.1
jsbarcode@3.11.5

Contributor guide

Open the contributing guide

Research direction

Start with the README SVG example and reproduce the reported Node.js v10 error using the shown xmldom setup. Trace the stack from renderers/shared.js through renderers/svg.js, then verify that the example runs without the getContext TypeError.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
backend, web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.