Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #2126
Closed
Open
Issue created Feb 12, 2019 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[BUG] javascript: unexpected token import

Created by: jacobweber

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

I'm using a Swagger 2 spec, with the javascript generator, on Mac OS 10.14.2, with node v8.12.0 and npm 6.4.1. I can't get the example code to work, regardless of the spec.

After I build it, I make a .tar.gz of the code, so I can install it with npm:

tar czvf /path/to/swagger.tar.gz /path/to/output

Then in my project, I run:

npm install
npm install /path/to/swagger.tar.gz

The last command outputs:

npm WARN deprecated babel@6.23.0: In 6.x, the babel package has been deprecated in favor of babel-cli. Check https://opencollective.com/babel to support the Babel maintainers

> fsevents@1.2.7 install /path/to/project/node_modules/fsevents
> node install

node-pre-gyp WARN Using needle for node-pre-gyp https download 
[fsevents] Success: "/path/to/project/node_modules/fsevents/lib/binding/Release/node-v57-darwin-x64/fse.node" is installed via remote
+ swagger_example@1.0.0
added 322 packages from 160 contributors and audited 1559 packages in 10.067s
found 0 vulnerabilities

Then when I try to use it, following the example:

var SwaggerExample = require('swagger_example');

I get an error:

/path/to/project/node_modules/swagger_example/src/index.js:15
import ApiClient from './ApiClient';
^^^^^^

SyntaxError: Unexpected token import
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:617:28)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)
    at Module.require (module.js:597:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/path/to/project/src/index.js:2:29)
openapi-generator version

4.0.0-SNAPSHOT

OpenAPI declaration file content or url

Works with any spec, e.g. https://gist.github.com/jacobweber/53422c873b34de07e9e715fdbb9cbc1d

Command line used for generation
java -jar /path/to/openapi-generator-cli.jar generate -i /path/to/spec.json -g javascript -o /path/to/output
Steps to reproduce

See above.

Related issues/PRs

This used to work with swagger-codegen.

Suggest a fix

None

Assignee
Assign to
Time tracking