swagger-api / swagger-api/swagger-codegen

[Javascript] Webpack 3.0 unexpected token ===

Open
#5,975 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: JavaScript/Node.js Issue: Workaround available
Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

Just helping any internet searchers coming around until Webpack fixes this.

If you are

  • using Webpack 3
  • with parser.amd = false as per the Readme

You will run into this issue https://github.com/webpack/webpack/issues/5198.

The problematic line for me is in ApiClient.prototype.isFileParam.

    if (typeof window === 'undefined' &&
        typeof require === 'function' && // <------ here
        require('fs') &&
        param instanceof require('fs').ReadStream) {
      return true;
    }
Swagger-codegen version

Tried with 2.2.0 and 2.2.2.

Swagger declaration file content or url
Command line used for generation
Steps to reproduce
  • require() Swagger generated files from Webpack 3.
Related issues
Suggest a Fix

Go back to the old hack using imports-loader?define=false which still works until the bug is fixed.

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

The report points to the generated JavaScript ApiClient.prototype.isFileParam code and the README setting parser.amd=false. Start by locating that generated code in the JavaScript templates, then reproduce requiring generated files with Webpack 3. Done when the generated client no longer triggers the reported unexpected-token failure under that setup.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, webpack
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.