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

Attempted import error: 'randexp' does not contain a default export (imported as 'i'). #7962

Closed
w0rmr1d3r opened this issue Mar 30, 2022 · 7 comments

Comments

@w0rmr1d3r
Copy link

Q&A (please complete the following information)

  • OS: macOS Big Sur 11.6.5
  • Browser: doesn't apply
  • Version: version of the browser?
  • Method of installation: npm
  • Swagger-UI version: 4.10.0
  • Swagger/OpenAPI version: don't now

Content & configuration

File package.json:

"swagger-ui-react": "^4.10.0",

Describe the bug you're encountering

To reproduce...

Steps to reproduce the behavior:

  1. Migrated from 4.1.2 to 4.10.0
  2. Run npm run build
  3. Obtained the error below
Creating an optimized production build...
Failed to compile.

./node_modules/swagger-ui-react/swagger-ui-es-bundle-core.js
Attempted import error: 'randexp' does not contain a default export (imported as 'i').

Expected behaviour

Able to run the command.

Screenshots

Additional context or thoughts

@tim-lai
Copy link
Contributor

tim-lai commented Mar 31, 2022

@w0rmr1d3r I'm running a project with swagger-ui-react@4.10.0 and can build without issues. There may be an issue with the configuration in your build tool. Perhaps you could provide a link to your project, and a community member might be able to help troubleshoot?

@w0rmr1d3r
Copy link
Author

Hi @tim-lai !
Thank you for your answer.

I can't share the project, since it's company internal. But I might be able to provide more info regarding the build tool.

What information may you need for it?

thanks

@tim-lai
Copy link
Contributor

tim-lai commented Apr 15, 2022

@w0rmr1d3r Any platform/environment details would be helpful. e.g. there are recent closed issues related to recent bundling changes where the users were using Typescript. Thanks.

@w0rmr1d3r
Copy link
Author

Hi @tim-lai
Let me provide more context:

I'm using React with version 17.0.2

Using these engines:

  "engines": {
    "node": "^16.13.0",
    "npm": "^8.1.0"
  },

Importing the library like so:

import SwaggerUI from 'swagger-ui-react';

Thought this was related to this, #7970 , upgraded to 4.10.3 but it reported the same failure.
Reviewed more issues such as:
#7935
#7944
#7893

And PRs such as:
#7946
#7927

I'm not an expert on this subject, found this post:
https://bobbyhadz.com/blog/javascript-does-not-contain-default-export
Which it seemed to me to be related to this issue.

This project is using randexp in

import RandExp from "randexp"

Which is a project that hasn't been updated in 4 years, is it possible to use another one instead? A newer one?

Thanks in advance!

@char0n
Copy link
Member

char0n commented May 16, 2022

Hi guys,

I haven't been able to reproduce this. If I run following code in Node.js engine:

import * as i from "randexp"; // i.default === RandExp
import RandExp from "randexp";

We're getting correct results. @w0rmr1d3r without providing more information, this issue will not be actionable. Could you please create a public GitHub repo with minimal steps to reproduce this problem?

webpack@5 handles it also well. I assume that the problem is somehow caused by your build system which has limited interoperability between ESM and CommonJS. But again without the GitHub repo with minal steps to reproduce, we cannot help more.

@w0rmr1d3r
Copy link
Author

Hello @char0n ,
Thank you for the information provided.

Since I can't share the entire repo because it's private and sharing a part of it wouldn't match the scenario, I'd rather look into it privately.
As discussed and tested, it might be more of an internal issue rather than related to the package.

Thank you again for your information. I will pass this issue to our teams 😄

@w0rmr1d3r
Copy link
Author

Hello @char0n ,

Managed to solve the issue.
We bumped the project, so it uses now:

Now using node v16.15.1 (npm v8.11.0)

And was able to bump from 4.1.2 to ^4.10.0, all I needed to do was add "randexp": "^0.5.3", in the devDependencies.

The build step of the project can now finish successfully, test pass and all.

Cheers!

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

Successfully merging a pull request may close this issue.

3 participants