swagger-api / swagger-api/swagger-ui

Parcel Build for Swagger-UI not working for v4.9 and greater.

Open
#8,340 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
29k
Forks
9.3k
Avg merge
2d 23h
Merged PRs (30d)
25

Description

Q&A
  • OS: macOS 13.1
  • Browser: Chrome, Firefox
  • Method of installation: npm
  • Swagger-UI version: 4.15.5
Content & configuration

The build setup and dependencies that I am using can be viewed in the following repo:
https://github.com/totakura/parcel-swagger-ui

  • parcel@2.8.2
  • swagger-ui@4.15.5

After running parcel for the first time, it gave the following message:

@parcel/resolver-default: Auto installing polyfill for Node builtin module "buffer"...

And added the following dependencies to the package.json

  • buffer@5.7.1
  • punycode@1.3.2
Describe the bug you're encountering

I am trying to do a simple import and instantiation of the swagger UI library, like so:

// app.js
import SwaggerUI from 'swagger-ui';

SwaggerUI({
  dom_id: '#swagger-ui'
});

I then get the following error message in the browser console:

Uncaught TypeError: Class extends value undefined is not a constructor or null

If I try to follow the stack trace, it looks like the error originates from memoizeN.js

// memoizeN.js
class Cache extends Map {
  delete(key) {
    const keys = Array.from(this.keys())
    const foundKey = keys.find(shallowArrayEquals(key))
    return super.delete(foundKey)
  }

  get(key) {
    const keys = Array.from(this.keys())
    const foundKey = keys.find(shallowArrayEquals(key))
    return super.get(foundKey)
  }

  has(key) {
    const keys = Array.from(this.keys())
    return keys.findIndex(shallowArrayEquals(key)) !== -1
  }
}

It's unclear to me why this would be the case, as Map should be defined in the browser.

To reproduce...

Steps to reproduce the behaviour:

  1. Install the latest version of parcel and swagger-ui
  2. Try to import swagger-ui in a javascript file using the default parcel config
  3. Open your browser and view the error message in the console.
Expected behavior

I would expect parcel to be able to build the code correctly.

It seems to correctly identify the need for buffer and Punycode polyfills. I can't understand why the error would originate with Map being undefined. Perhaps the browser is not correctly identifying where the exception originates.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the import in app.js with Parcel 2.8.2 and swagger-ui 4.15.5, then inspect src/helpers/memoizeN.js and the browser bundle around the reported Map error. Compare Parcel's generated output and polyfill handling to identify why the default build fails. Done when the default Parcel build instantiates SwaggerUI without the console TypeError.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend, web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.