In my Ionic 4 app, I am utilizing version 2.3.4 of the npm package called convert-units
.
To install this package in my Ionic 4 application, I used the CLI command: npm i convert-units --save
However, upon importing the library with
import { convert } from "convert-units"
and trying to use a function like convert().list()
in my component file, an error is being displayed.
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 have attempted the following methods:
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 included this code in index.html which resolved the issue.
<script>
var global = global || window;
</script>