device-uuid icon indicating copy to clipboard operation
device-uuid copied to clipboard

DeviceUUID is not a constructor

Open rufrajput opened this issue 3 years ago • 11 comments

can someone help with this error? I am facing this error while running a desktop app build with js, svelte and go.

image

rufrajput avatar Sep 07 '21 17:09 rufrajput

That is because you are importing and setting it as a variable so you would technically need to write new DeviceUUID.DeviceUUID().get()

johnpaulmedina avatar Apr 21 '22 17:04 johnpaulmedina

I'm having the same issue with VueJS.

import { DeviceUUID } from "device-uuid";
let uuid = new DeviceUUID().get();

It works fine when running with npm run dev but fails when application is built with npm run build.

TypeError: deviceUuid.DeviceUUID is not a constructor

So if I do the following import: import du from 'device-uuid'

And try to log the value of the object into the console console.log("This is DU:", du);

I get the following:

npm run dev This is DU: {DeviceUUID: ƒ}

npm run build This is DU: {}

So basically as I can see nothing gets imported as du.

denisvitez avatar May 26 '22 11:05 denisvitez

I'm having the same issue with VueJS.

import { DeviceUUID } from "device-uuid";
let uuid = new DeviceUUID().get();

It works fine when running with npm run dev but fails when application is built with npm run build.

TypeError: deviceUuid.DeviceUUID is not a constructor

So if I do the following import: import du from 'device-uuid'

And try to log the value of the object into the console console.log("This is DU:", du);

I get the following:

npm run dev This is DU: {DeviceUUID: ƒ}

npm run build This is DU: {}

So basically as I can see nothing gets imported as du.

Hey, man, I have the same problem. How did you solve it

yimingxie avatar Jul 07 '22 15:07 yimingxie

I'm having the same issue with VueJS.

import { DeviceUUID } from "device-uuid";
let uuid = new DeviceUUID().get();

It works fine when running with npm run dev but fails when application is built with npm run build. TypeError: deviceUuid.DeviceUUID is not a constructor So if I do the following import: import du from 'device-uuid' And try to log the value of the object into the console console.log("This is DU:", du); I get the following: npm run dev This is DU: {DeviceUUID: ƒ} npm run build This is DU: {} So basically as I can see nothing gets imported as du.

Hey, man, I have the same problem. How did you solve it

Hey, I ended up dropping the library altogether and reworked the application by just using UUID - https://www.npmjs.com/package/vue-uuid. I then store this UUID in local storage and use it on subsequent session refreshes.

denisvitez avatar Jul 08 '22 08:07 denisvitez

This worked for me in react web app -

import DeviceUUID from "device-uuid"; var deviceUUID = new DeviceUUID.DeviceUUID().get(); console.log(deviceUUID)

devapurva avatar Sep 25 '23 11:09 devapurva

So what's the solution on build?

umrzoq-toshkentov avatar Feb 02 '24 10:02 umrzoq-toshkentov

Make sure you are using import { DeviceUUID } from "device-uuid"; and not import DeviceUUID from "device-uuid"; as the latter will give you that error. DeviceUUID is, apparently, not the default export from device-uuid which causes this error.

davidgs avatar Apr 10 '24 11:04 davidgs

So what's the solution on build?

@umrzoq-toshkentov Did you find any solution for this not working issue after build?

shifanpark avatar Jun 10 '24 14:06 shifanpark

So what's the solution on build?

@umrzoq-toshkentov Did you find any solution for this not working issue after build?

not yet, seems to bee need to fix it.

umrzoq-toshkentov avatar Jun 10 '24 14:06 umrzoq-toshkentov

I had the same problem.

It seems a solution has been found on StackOverflow, which worked for me.

In your vite.config.js, add the following to the configuration and then build as normal.

  build: {
      commonjsOptions: { include: [] },
    },
    optimizeDeps: {
      disabled: false,
    },

EdGaere avatar Jul 07 '24 14:07 EdGaere

Yeah that optimizeDeps disabling now says in bright yellow when production building with Vite/ Rollup/whatever:

(!) Experimental optimizeDeps.disabled and deps pre-bundling during build were removed in Vite 5.1.
   Setting it to false now has no effect.
   Please remove optimizeDeps.disabled from your config.

And... it doesn't fix it. I think I need a different solution.

phil-w avatar Jul 09 '24 10:07 phil-w