OpenAPITools / OpenAPITools/openapi-generator
[BUG] javascript: unexpected token import
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Run the Java generator command from the report with the linked example spec, then inspect the generated src/index.js and the installed package entry point. Reproduce the failure with Node v8 and verify that the generated package can be loaded with require without the unexpected token import error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100