Issue with rollup
Installed via npm
tried import {Diff2Html} from 'diff2html;
but get
path (imported by node_modules/diff2html/src/hoganjs-utils.js, commonjs-external:path) (!) Missing global variable name Use output.globals to specify browser global variable names corresponding to external modules path (guessing 'path')
I have no idea what that might be. My experience with Typescript is very limited.
If you find anything please report here. Maybe @sss0791 can help? He was the last person to use this with Typescript.
I tried to import Diff2Html in an Angular 6 project but faced the same issue.
The only (ugly) solution I found so far is to copy the diff2html dist files in my project assets.
angular.json
"assets": [
"src/favicon.ico",
"src/assets",
{
"glob": "**/*.min.*",
"input": "node_modules/diff2html/dist/",
"output": "assets/diff2html/"
}
]
And import them from index.html the usual way:
<!-- Diff2Html -->
<link rel="stylesheet" type="text/css" href="assets/diff2html/diff2html.min.css">
<script type="text/javascript" src="assets/diff2html/diff2html.min.js"></script>
</head>
Finally to use Diff2Html in a component, I have to import it from the window object:
const Diff2Html = (window as any).Diff2Html;
Importing this library in TypeScript (import {Diff2Html} from 'diff2html;) always ended in compilation issues because of the var path = require('path'); line in the file hoganjs-utils.js.
I found a better solution.
I simply include the diff2html files in angular.json:
"scripts": [
"node_modules/diff2html/dist/diff2html.min.js"
],
( you may also need to add the css, I use my own to handle the resizing of the diff container using flexbox).
And keep importing the Diff2Html from the window object:
const Diff2Html = (window as any).Diff2Html
@geraldpereira thanks for your help. If you have any suggestions regarding what I can change to improve this let me know.
Sorry I'm bumping up the old thread, I am having the same issue when using with typescript.
Importing this library in TypeScript (
import {Diff2Html} from 'diff2html;) always ended in compilation issues because of thevar path = require('path');line in the file hoganjs-utils.js.
@geraldpereira Can you elaborate why does typescript give an error in this line? Does it need additional typings for this? I'd be willing to make an effort to fix this, but I'm not sure I understand what's causing typescript to give error.
Sorry I'm bumping up the old thread, I am having the same issue when using with typescript.
Importing this library in TypeScript (
import {Diff2Html} from 'diff2html;) always ended in compilation issues because of thevar path = require('path');line in the file hoganjs-utils.js.@geraldpereira Can you elaborate why does typescript give an error in this line? Does it need additional typings for this? I'd be willing to make an effort to fix this, but I'm not sure I understand what's causing typescript to give error.
@shileen It has nothing to do with typings.
Just do a : npm install path