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

quantile function of Beta distribution is broken on production build with Next.js #3011

Open
2 tasks done
bvdmitri opened this issue Oct 15, 2024 · 8 comments
Open
2 tasks done
Labels
Bug Something isn't working. Needs Discussion Needs further discussion. Statistics Issue or pull request related to statistical functionality.

Comments

@bvdmitri
Copy link

Description

I have an application written in Next.js and some code that uses beta distribution from '@stdlib/stats-base-dists/dist'. I noticed that the quantile function is completely broken while building the application in production mode (next build && next start). For example the output in Chrome console:

> dist = new window.beta_test.Beta(5, 5) // I did an ugly hack window.beta_test = beta in the code
w {}
> dist.quantile(0.1)
0.9999999996744877
> dist.quantile(0.5)
4.6663115970492885e-302

The quantile function works as expected if I run the application in the development mode (next dev)

> dist = new window.beta_test.Beta(5, 5)
t {}
> dist.quantile(0.1)
0.30096876359321467
> dist.quantile(0.5)
0.5

I'm not sure if this is the case with other distributions

Related Issues

Related issues # , # , and # .

Questions

No.

Demo

No response

Reproduction

  • a
  • b
  • c

Expected Results

No response

Actual Results

No response

Version

0.2.2

Environments

Chrome

Browser Version

129.0.6668.91

Node.js / npm Version

No response

Platform

MacOS

Checklist

  • Read and understood the Code of Conduct.
  • Searched for existing issues and pull requests.
@stdlib-bot
Copy link
Contributor

👋 Hi there! 👋

And thank you for opening your first issue! We will get back to you shortly. 🏃 💨

@kgryte
Copy link
Member

kgryte commented Oct 15, 2024

@Planeshifter Any ideas here?

@kgryte kgryte added Bug Something isn't working. Statistics Issue or pull request related to statistical functionality. labels Oct 15, 2024
@Planeshifter
Copy link
Member

Planeshifter commented Oct 16, 2024

Currently am unable to reproduce the issue in a Next.js app; similarly attached beta distribution namespace to beta_test and ran the above commands. I am seeing the expected results.

@bvdmitri Does the same happen when loading @stdlib/stats-base-dists instead of the optimized distribution bundles from @stdlib/stats-base-dists/dist? If so, would you be able to upload a repository with a reproduction of the bug?

@bvdmitri
Copy link
Author

bvdmitri commented Oct 16, 2024

Hey @Planeshifter , thanks for checking! Yes, the issue also happens when I change the import statement to @stdlib/stats-base-dists.

console.log(new beta.Beta(5,5).quantile(.5))

outputs 4.6663115970492885e-302. This is on Next.js 14.2.15 (last release) and this is only happens if I use production build with pnpm build && pnpm start. This is not happening in the development mode with pnpm dev. I, unfortunately, cannot share the codebase.

However, I also tried Next.js 15.0 (still in beta afaiu) and the issue is not present there and everything works as expected. That makes me think that some configuration options have changed for the build process. Do you know what in principle can cause the mathematical operations to be malformed during bundling in js? I'm not an expert in js/ts bundlers build processes so this is as far as I can go.

@kgryte
Copy link
Member

kgryte commented Oct 16, 2024

I suppose it could be possible that minification is reordering operations, but one would need to confirm by examining the bundled output.

@bvdmitri
Copy link
Author

Here is the link to the reproducer https:/bvdmitri/nextjs-stdlib-bug

import { beta } from '@stdlib/stats-base-dists';

export default function Home() {
  const result = new beta.Beta(5, 5).quantile(0.5);
  return <div>{result}</div>;
}

Image

@bvdmitri
Copy link
Author

I also wanted to file this issue within Next.js repository, but since it is fixed on the next beta version its not considered as a bug. But updating our codebase to the latest unreleased beta of Next.js is somewhat disruptive, so any help here is appreciated.

@bvdmitri
Copy link
Author

For other people who also encounter the same issue I was able to hot-fix it with the following option in next.config.mjs

const nextConfig = {
    swcMinify: false
};

@kgryte kgryte added the Needs Discussion Needs further discussion. label Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working. Needs Discussion Needs further discussion. Statistics Issue or pull request related to statistical functionality.
Projects
None yet
Development

No branches or pull requests

4 participants