How to import this lib into react typescript?
See original GitHub issueI am trying to import this lib into react typescript project.
import html2pdf from 'html2pdf.js'
Then create a typing.d.ts below
declare module 'html2pdf.js';
However, my project reports the below errors
fromRequireContextWithGlobalFallback.js:21 TypeError: _typeof is not a function
at html2pdf.js:16
at html2pdf.js:9
at Object../node_modules/html2pdf.js/dist/html2pdf.js (html2pdf.js:10)
I opened the source file in chrome
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
/**
* html2pdf.js v0.9.1
* Copyright (c) 2018 Erik Koopmans
* Released under the MIT License.
*/
(function (global, factory) {
(typeof exports === "undefined" ? "undefined" : _typeof(exports)) === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('es6-promise/auto'), require('jspdf'), require('html2canvas')) : typeof define === 'function' && define.amd ? define(['es6-promise/auto', 'jspdf', 'html2canvas'], factory) : global.html2pdf = factory(null, global.jsPDF, global.html2canvas);
})(this, function (auto, jsPDF, html2canvas) {
'use strict';
jsPDF = jsPDF && jsPDF.hasOwnProperty('default') ? jsPDF['default'] : jsPDF;
html2canvas = html2canvas && html2canvas.hasOwnProperty('default') ? html2canvas['default'] : html2canvas;
var _typeof = typeof Symbol === "function" && _typeof(Symbol.iterator) === "symbol" ? function (obj) {
return _typeof(obj);
} : function (obj) {
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : _typeof(obj);
};
May I ask what’s wrong with my config?
Thank you
Issue Analytics
- State:
- Created 4 years ago
- Comments:7
Top Results From Across the Web
Can I use third-party libraries with React and TypeScript?
You can import Javascript libraries in your Typescript project. I do that all the time, unfortunately. Some libraries have community-typed ...
Read more >Build a component library with React and TypeScript
Learn to create a component library with React and TypeScript in this in-depth tutorial that includes testing and deploying to npm.
Read more >How to build a React library using TypeScript
A step by step guide to setup a React Library from scratch using TypeScript, and publish it to NPM.
Read more >TypeScript and React: Getting Started - fettblog.eu
We use React for client-side development. That's why we need to import some libraries to support this. In our case, we import ES...
Read more >How to create a local React + TypeScript library that I can use ...
1 Answer · Initialize the project · Add TypeScript · Add React · Add a UI component · Add Rollup · Using the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
No Luck, I used html2canvas and jsPDF in the end.
html2pdf.jsseems quite inactive now.For me it works in TypeScript: