Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError in production builds #28192

Open
MacjaZival opened this issue Jul 17, 2024 · 7 comments
Open

TypeError in production builds #28192

MacjaZival opened this issue Jul 17, 2024 · 7 comments

Comments

@MacjaZival
Copy link

Environment

Nuxt project info:


  • Operating System: Linux
  • Node Version: v22.4.1
  • Nuxt Version: 3.12.0
  • CLI Version: 3.12.0
  • Nitro Version: 2.9.7
  • Package Manager: npm@10.8.2
  • Builder: -
  • User Config: compatibilityDate, devtools
  • Runtime Modules: -
  • Build Modules: -

Reproduction

Create a new nuxt project (npx nuxi@latest init test) install device-uuid (npm i device-uuid) and use the package on the client. You can just replace app.vue with:

<script setup>
import { DeviceUUID } from 'device-uuid';
function test() {
  const uuid = new DeviceUUID().get();
  console.log('Worked', uuid);
}
</script>
<template>
  <div>
    <button @click="test">Test</button>
  </div>
</template>

This will work if you run it with npm run dev but will not work if you run it with npm run build && node .output/server/index.mjs throwing something along the lines of TypeError: Od.DeviceUUID is not a constructor

Describe the bug

Package bundling seems to work incorrectly in production builds.

Additional context

This worked a few days ago but now does not anymore. I tried different node versions, different nuxt versions, vue versions, vite versions,... assuming that a package updated and broke things but nothing helped.

Logs

No response

@huang-julien
Copy link
Member

@MacjaZival
Copy link
Author

https://stackblitz.com/edit/nuxt-starter-9g1eks?file=README.md

I don't know if this is just a sandbox for other people to try the bug or if it is meant to be a solution but it fails with the same error as before (locally and on StackBlitz).

@ttisak
Copy link

ttisak commented Jul 18, 2024

I encountered the same issue in recent days, although the provided example is also failing in the development environment (because of SSR). Here is a working example (in development), but with the same issues in production as described by @MacjaZival.

https://stackblitz.com/edit/nuxt-starter-dwx7jw?file=app.vue

@danielroe
Copy link
Member

This is likely an upstream bug either in device-uuid or in Nitro.

Would you see if you can reproduce this in pure Nitro (reproduction sandbox)?

@MacjaZival
Copy link
Author

I do not understand how the web server could impact a package only used on the client. My first assumption was that something went wrong with bundling. Also if it is a problem with device-uuid (that was last updated 7 years ago) why was it working a few days ago and then suddenly stopped and also why does it still work in development (and not in production)?

I would love to try and reproduce it in the reproduction sandbox but I don't know what I am trying to reproduce here... as I stated this package is only meant to be used on the client. If I am missing something here please explain it to me 😅.

@NamesMT
Copy link

NamesMT commented Jul 21, 2024

@MacjaZival

This worked a few days ago but now does not anymore, I tried different nuxt versions
Why was it working a few days ago and then suddenly stopped and also why does it still work in development (and not in production)?

This means the problem could be a recent update in Nuxt's sub-dependency (could be Nitro in this case, as development is working and build is not).

I also encounter a similar issue with nano-memoize and have created an issue over at Nitro: nitrojs/nitro#2629, might be worth adding to your watchlist

@ferreraa
Copy link

I am having the same issue when building an app with vite instead of vue-cli-service.
This is not happening when running a dev server but it does happen when running from my dist folder after building the app.

Several issues are open regarding this on the device-uuid github page

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants