I am using the convert-units 2.3.4 npm package in ionic 4.
I installed this package in my ionic 4 app using cli - npm i convert-units --save
But when I am importing the library using import { convert } from "convert-units" and using one of the functions like convert().list() in my component file then it is showing an error.
import { convert } from "convert-units";
calculatePrice(){
console.log(convert().list());
}
Uncaught ReferenceError: global is not defined
at Object../node_modules/lodash.support/index.js (index.js:30)
at __webpack_require__ (bootstrap:83)
at Object../node_modules/lodash._basecreatecallback/index.js (index.js:12)
at __webpack_require__ (bootstrap:83)
at Object../node_modules/lodash.foreach/index.js (index.js:9)
at __webpack_require__ (bootstrap:83)
at Object../node_modules/convert-units/lib/index.js (index.js:3)
at __webpack_require__ (bootstrap:83)
at Module../src/app/components/ingredients-value/ingredients-value.component.ts (ingredients-value.component.ts:9)
at __webpack_require__ (bootstrap:83)
I already tried this method:
const convert = require('convert-units');
or
var convert = require('../../../../node_modules/convert-units/lib')
, assert = require('assert')
, tests = {}
, ACCURACY = 1/1000
, percentError = require('../../../../node_modules/convert-units/lib/percentError');
Solution:- I add this code in index.html. This solved my issue.
<script>
var global = global || window;
</script>