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

External library import in utils - nuxt build bug or misuse? #26375

Closed
zguig52 opened this issue Mar 19, 2024 · 4 comments
Closed

External library import in utils - nuxt build bug or misuse? #26375

zguig52 opened this issue Mar 19, 2024 · 4 comments

Comments

@zguig52
Copy link

zguig52 commented Mar 19, 2024

Environment

On stackblitz:

  • Operating System: Linux
  • Node Version: v18.18.0
  • Nuxt Version: 3.11.1
  • CLI Version: 3.11.0
  • Nitro Version: 2.9.4
  • Package Manager: npm@10.2.3
  • Builder: -
  • User Config: devtools
  • Runtime Modules: -
  • Build Modules: -

On dev machine:

  • Operating System: Linux
  • Node Version: v20.11.1
  • Nuxt Version: 3.11.1
  • CLI Version: 3.11.0
  • Nitro Version: 2.9.4
  • Package Manager: yarn@1.22.21
  • Builder: -
  • User Config: devtools
  • Runtime Modules: -
  • Build Modules: -

Reproduction

https://stackblitz.com/edit/github-qytiun?file=utils%2Fimport.ts

Describe the bug

I create a helper function in the utils folder. I use an external javascript package.

Code is working fine in dev environment, but when I generate the build and start it, there is an issue on server side, the library is not imported: "bigDecimal.add is not a function"

When I enforce the component to be client side only, build is OK, but I cannot use SSR for it.

Is it not the right way to import an external library and use custom functions based on it or a nuxt build issue (missing the import for the server side running code?).

Additional context

This bug is not linked to the new nuxt version. It was already there before v3.11.

I have read carefully the documentation here and did not found what I was doing wrong:
https://nuxt.com/docs/guide/directory-structure/utils

Logs

No response

Copy link

stackblitz bot commented Mar 19, 2024

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@danielroe
Copy link
Member

This is a packaging issue in that library.

You can transpile it:

// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
  devtools: { enabled: true },
  build: {
    transpile: ['js-big-decimal']
  }
})

@danielroe danielroe closed this as not planned Won't fix, can't repro, duplicate, stale Mar 19, 2024
@zguig52
Copy link
Author

zguig52 commented Mar 19, 2024

Thanks a lot for your reply! Do you have any details that I can give to the lib maintainers on how to properly package it?

@meirroth
Copy link

@danielroe Can you please guide us how to update the package so it can be used in Nuxt without transpile? Ran into the same issue with featurevisor/featurevisor#269

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

3 participants