L5-Swagger icon indicating copy to clipboard operation
L5-Swagger copied to clipboard

Uncaught SyntaxError: Unexpected token '<'. Uncaught ReferenceError: SwaggerUIBundle is not defined at window.onload

Open illia-code-care opened this issue 3 years ago • 9 comments

  • L5-Swagger Version: 8.0
  • PHP Version: 8.0
  • OS: Ubuntu

Description:

Locally works. After installing on server got:

Uncaught SyntaxError: Unexpected token '<' Uncaught ReferenceError: SwaggerUIBundle is not defined at window.onload

Steps To Reproduce

  1. composer require ..
  2. php artisan l5-swagger:generate
  3. php artisan vendor:publish --provider "L5Swagger\L5SwaggerServiceProvider"

After accessing /documentation there are 2 errors in console.

illia-code-care avatar Jan 10 '22 19:01 illia-code-care

Looks like something is wrong with your resources/views/index.blade.php - https://github.com/DarkaOnLine/L5-Swagger/blob/master/resources/views/index.blade.php

Can you check if it is published correctly and you don't see any syntax error in file?

DarkaOnLine avatar Jan 11 '22 09:01 DarkaOnLine

@DarkaOnLine As I see I have syntax error in this files:

In each of them I get error: Uncaught SyntaxError: Unexpected token '<'. But I can not get into them.

And I guess that's why after this lines I get: Uncaught ReferenceError: SwaggerUIBundle is not defined at window.onload because I think Bundle depends on that 2 scripts.

illia-code-care avatar Jan 11 '22 10:01 illia-code-care

@DarkaOnLine

I have copied github blade to my file but still the same. I think there are 2 errors in swagger-ui-bundle.js, swagger-ui-standalone-preset.js each of them.

I tried to remove this 2 lines. And I got just last error: "Uncaught ReferenceError: SwaggerUIBundle is not defined at window.onload" but maybe it depends on those scripts.

As locally works, I thought that problem can be in server nginx but it is really strange that it can find files but just got syntax errors.

illia-code-care avatar Jan 11 '22 10:01 illia-code-care

image

Also in source I see that here is some error but can not inspect here what the error.

illia-code-care avatar Jan 11 '22 10:01 illia-code-care

We require "swagger-api/swagger-ui": "^3.0" in our composer.json. You can try to use older version of this in your composer - assuming swagger-ui have a bug in their release :(

DarkaOnLine avatar Jan 11 '22 10:01 DarkaOnLine

image

illia-code-care avatar Jan 11 '22 10:01 illia-code-care

I have tried with Chrome, Vivaldi but the same.. @DarkaOnLine Ok I gonna try older version, thanks!

Btw, i have in composer just ""darkaonline/l5-swagger".No swagger-api

The main strange for me is that locally everything works, so maybe it's nginx..

illia-code-care avatar Jan 11 '22 10:01 illia-code-care

Is there any update on this? I'm having the same issue when I'm trying to load the documentation.

swagger-ui-bundle.js…de593c255f23632e2:1 Uncaught SyntaxError: Unexpected token '<' (at swagger-ui-bundle.js…593c255f23632e2:1:1)

swagger-ui-standalon…8b3f0c5a355d677f4:1 Uncaught SyntaxError: Unexpected token '<' (at swagger-ui-standalon…3f0c5a355d677f4:1:1)

documentation:37 Uncaught ReferenceError: SwaggerUIBundle is not defined
    at window.onload (documentation:37:20)

awwwer avatar Jun 15 '22 13:06 awwwer

Having the same issue, any update?

adeel94mirza avatar Jun 23 '22 17:06 adeel94mirza

image

Script tags crawled up a few characters. After I changed title in the config file to English, the problem was solved. Probably a multibyte string issue.

shk-webpr avatar Sep 30 '22 14:09 shk-webpr

For me, the problem was mbstring.func_overload = 2.

shk-webpr avatar Sep 30 '22 15:09 shk-webpr

At today, 25/01/2023 problem persist.

castris 2023-01-25 a las 12 28 11

@shk-webpr You can explain you solution ? Thanks.

abkrim avatar Jan 25 '23 11:01 abkrim

@abkrim, my solution was one of these:

  • setting title value in English in config file l5-swagger.php; image

  • setting mbstring.func_overload=0 in PHP .ini files.

shk-webpr avatar Jan 25 '23 13:01 shk-webpr

try add the below config to NginX server config

charset utf-8;

zhangjiaying avatar Feb 27 '23 10:02 zhangjiaying

My solution was adding the method serveFiles

const CSS_URL = 'https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/4.1.0/swagger-ui.min.css';

const options = { customCssUrl: CSS_URL, };

router.use('/api-docs', swaggerUi.serveFiles(swaggerDoc, options), swaggerUi.setup(swaggerDoc, options));

I had to add the styles manually. it work for me :)

danexcode avatar Sep 28 '23 23:09 danexcode

I will add to my solution the calling of swagger-ui-dist package,

const { SwaggerUIBundle, SwaggerUIStandalonePreset } = require('swagger-ui-dist');

I made tests and that line is necesary

danexcode avatar Oct 11 '23 16:10 danexcode

I will add to my solution the calling of swagger-ui-dist package,

const { SwaggerUIBundle, SwaggerUIStandalonePreset } = require('swagger-ui-dist');

I made tests and that line is necesary

This works for me. I have just add this and it works fine. Thanks bro

MalikSaadTanveer avatar Oct 26 '23 10:10 MalikSaadTanveer

I will add to my solution the calling of swagger-ui-dist package,

const { SwaggerUIBundle, SwaggerUIStandalonePreset } = require('swagger-ui-dist');

I made tests and that line is necessary

I confirm that this method also works for me. Thank you for your help. For future reference, this is my repository. repo

nani-samireddy avatar Nov 07 '23 10:11 nani-samireddy

During local development I forgot to set FORCE_HTTPS=false in .env.

So it tried to load scripts from https://localhost and resulted into a blank page with this error in a console.

SirPeace avatar Dec 25 '23 13:12 SirPeace