Q&A (please complete the following information)
- OS: MacOS 10.13.6
- Browser: All (Firefox, Brave)
- Version:
- Method of installation: npm
- Swagger-UI version: 4.15.0
- Swagger/OpenAPI version: OpenAPI 3.0.1
Content & configuration
Bug is unrelated to Swagger content/config.
(Also fails on node v17.9.1)
package.json
{
"name": "bugger",
"version": "0.1.0",
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start"
},
"dependencies": {
"next": "12.3.1",
"react": "18.2.0",
"react-dom": "18.2.0",
"swagger-ui-react": "^4.15.0"
}
}
pages/index.js
import SwaggerUI from 'swagger-ui-react';
import 'swagger-ui-react/swagger-ui.css';
const spec = {
"openapi": "3.0.1",
"info": {
"title": "title",
"description": `description`,
version: 'version'
},
"paths": {
// valid paths..
}
};
export default () => <SwaggerUI spec={spec} />;
Describe the bug you're encountering
Following your example code, in a minimum next-app installation, swagger ALWAYS throws this error:
SyntaxError: Cannot use import statement outside a module
/node_modules/swagger-ui-react/commonjs.js:10:53
Caused by this line import SwaggerUI from 'swagger-ui-react';
Even when converted to older style const SwaggerUI = require('swagger-ui-react');, the error is thrown.
To reproduce...
Steps to reproduce the behavior:
- npx create-next-app@latest bugger && cd bugger
- paste the
pages/index.js and package.json contents shown above
- npm i
- npm run dev
- load
http://localhost:3000/ in browser
- See error
Expected behavior
Expecting not to see SyntaxError: Cannot use import statement outside a module
Additional context or thoughts
The same error occurs during Vercel deployments.
I've successfully used SwaggerUI on macOS more modern that this 10.13.6 machine.
Even though both macOS are otherwise using identical versions of node/nextjs/react, etc.
Q&A (please complete the following information)
Content & configuration
Bug is unrelated to Swagger content/config.
(Also fails on node v17.9.1)
package.jsonpages/index.jsDescribe the bug you're encountering
Following your example code, in a minimum next-app installation, swagger ALWAYS throws this error:
SyntaxError: Cannot use import statement outside a module/node_modules/swagger-ui-react/commonjs.js:10:53Caused by this line
import SwaggerUI from 'swagger-ui-react';Even when converted to older style
const SwaggerUI = require('swagger-ui-react');, the error is thrown.To reproduce...
Steps to reproduce the behavior:
pages/index.jsandpackage.jsoncontents shown abovehttp://localhost:3000/in browserExpected behavior
Expecting not to see
SyntaxError: Cannot use import statement outside a moduleAdditional context or thoughts
The same error occurs during Vercel deployments.
I've successfully used
SwaggerUIon macOS more modern that this10.13.6machine.Even though both macOS are otherwise using identical versions of node/nextjs/react, etc.