scottie1984 / swagger-ui-express

Adds middleware to your express app to serve the Swagger UI bound to your Swagger document. This acts as living documentation for your API hosted from within your app.
MIT License
1.41k stars 225 forks source link

Vercel: Unexpected token < in JSON at position 1 #293

Closed Hazelwu2 closed 2 years ago

Hazelwu2 commented 2 years ago

Hi, I'm using vercel to deploy swagger api document

This is my full code.

/* eslint-disable import/order */
const express = require('express')
const app = express()
const path = require('path')

// Router
const swaggerUi = require('swagger-ui-express')
const YAML = require('yamljs')

// Swagger
const swaggerPath = path.resolve(__dirname, './swagger.yml')
const swaggerDocument = YAML.load(swaggerPath)
// const cssOptions = require('./utils/swagger.js')

var options = {
  explorer: true
};

// API Document
app.use(
  '/apidoc',
  swaggerUi.serve,
  swaggerUi.setup(swaggerDocument, options),
)

app.use(express.json())

module.exports = app

Problem

When I run local environment is work. It has correctly loaded css style. CleanShot 2022-05-02 at 16 05 11

But running at Vercel Production, It's doesn't work. Dev Tools show error

DevTools failed to load source map: Could not parse content for https://metawall-backend-git-feature-express-ayugioh2003.vercel.app/apidoc/swagger-ui-bundle.js.map: Unexpected token < in JSON at position 1

DevTools failed to load source map: Could not parse content for https://metawall-backend-git-feature-express-ayugioh2003.vercel.app/apidoc/swagger-ui-standalone-preset.js.map: Unexpected token < in JSON at position 1

CleanShot 2022-05-02 at 16 01 42

CleanShot 2022-05-02 at 16 07 05

I don't understand why this error occurs, cannot load css style, I'm not sure how to fix this. I think it is vercel problem, same code deploy to Heroku, it's work! Is there any idea?

scottie1984 commented 2 years ago

Not sure - I guess this would need raised with Vercel - perhaps something to do with expected file types for your application?