biggora / device-uuid

Fast browser device uuid generation library. Written in pure JavaScript, no dependencies.
MIT License
183 stars 96 forks source link

DeviceUUID is not a constructor #14

Open rufrajput opened 3 years ago

rufrajput commented 3 years ago

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

image

johnpaulmedina commented 2 years ago

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

denisvitez commented 2 years ago

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.

yimingxie commented 2 years ago

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

denisvitez commented 2 years ago

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.

devapurva commented 12 months ago

This worked for me in react web app -

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

umrzoq-toshkentov commented 7 months ago

So what's the solution on build?

davidgs commented 5 months ago

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.

shifanpark commented 3 months ago

So what's the solution on build?

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

umrzoq-toshkentov commented 3 months ago

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.

EdGaere commented 2 months ago

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,
    },
phil-w commented 2 months ago

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.