0

I am trying to get the device information from the application which is being built using Vue. We are using device-uuid.js library to capture the information The installation is done by executing below command

 npm install device-uuid --save

and I can see device-uuid is listed in node modules.

Below is the Vue code.

<template>
 <div class="container">
 <div class="screen">
 </div>
 </div>
</template>

<script>
 import axios from "axios";
 import DeviceUUID from "device-uuid";

 export default {
 name: "ph",
 components: {
    NB,
 },

props: ["text15", "no", "place", "next"],
data:()=>({
 key1 ='',
 key2 = ''
}),

created() {
  this.loadPage();
  this.retrieveFormValues();
  this.listenToRouter();
  this.getDeviceType();
 },
 methods: {

 getDeviceType:function(){
  var du = new DeviceUUID.parse();
  var dua = [
    du.language,
    du.platform,
    du.os,
    du.cpuCores,
    du.isAuthoritative,
    du.silkAccelerated,
    du.isKindleFire,
    du.isDesktop,
    du.isMobile,
    du.isTablet,
    du.isWindows,
    du.isLinux,
    du.isLinux64,
    du.isMac,
    du.isiPad,
    du.isiPhone,
    du.isiPod,
    du.isSmartTV,
    du.pixelDepth,
    du.isTouchScreen
  ];
  console.log('dua',dua )
 }
};
 </script>

This is resulting in below error

ReferenceError: DeviceUUID is not defined
getDeviceType PH.vue:115
created PH.vue:110
VueJS 32
<anonymous> main.js:47
js app.js:5514
__webpack_require__ app.js:854
fn app.js:151
1 app.js:5562
__webpack_require__ app.js:854
checkDeferredModules app.js:46
<anonymous> app.js:994
<anonymous> app.js:997

What is that I am missing during import

Maverick
  • 397
  • 1
  • 4
  • 18
  • You're missing nothing. This error is impossible under normal circumstances. Your code is either differs from what you posted, or you have some local problem, e.g. a file with incorrect code was cached. Try to clean dev server cache and restart it – Estus Flask Apr 01 '22 at 18:51
  • Now I am getting this error in console. TypeError: device_uuid__WEBPACK_IMPORTED_MODULE_9___default.a.parse is not a constructor – Maverick Apr 01 '22 at 18:53
  • If an instance is supposed to have parse method then there's a mistake, should be `new DeviceUUID()...` – Estus Flask Apr 01 '22 at 19:00
  • As per this documentation https://www.npmjs.com/package/device-uuid it has. Any inputs on how to fix it? – Maverick Apr 01 '22 at 19:20
  • It's this problem https://stackoverflow.com/questions/3034941/can-we-omit-parentheses-when-creating-an-object-using-the-new-operator – Estus Flask Apr 01 '22 at 20:26

1 Answers1

0

This https://github.com/biggora/device-uuid/issues/15 is what you are searching for, probably. Basically you should change the import from:

import DeviceUUID from "device-uuid";

To:

import { DeviceUUID } from 'device-uuid';

And a () should by added in DeviceUUID constructor call:

new DeviceUUID().parse()
Pudindin
  • 1
  • 1