device-uuid
device-uuid copied to clipboard
DeviceUUID is not a constructor
can someone help with this error? I am facing this error while running a desktop app build with js, svelte and go.
That is because you are importing and setting it as a variable so you would technically need to write new DeviceUUID.DeviceUUID().get()
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.
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 withnpm 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
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 withnpm 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 consoleconsole.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.
This worked for me in react web app -
import DeviceUUID from "device-uuid";
var deviceUUID = new DeviceUUID.DeviceUUID().get();
console.log(deviceUUID)
So what's the solution on build?
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.
So what's the solution on build?
@umrzoq-toshkentov Did you find any solution for this not working issue after build?
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.
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,
},
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.