L5-Swagger
L5-Swagger copied to clipboard
Uncaught SyntaxError: Unexpected token '<'. Uncaught ReferenceError: SwaggerUIBundle is not defined at window.onload
- 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
- composer require ..
- php artisan l5-swagger:generate
- php artisan vendor:publish --provider "L5Swagger\L5SwaggerServiceProvider"
After accessing /documentation there are 2 errors in console.
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 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.
@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.
Also in source I see that here is some error but can not inspect here what the error.
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 :(
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..
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)
Having the same issue, any update?
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.
For me, the problem was mbstring.func_overload = 2.
At today, 25/01/2023 problem persist.
@shk-webpr You can explain you solution ? Thanks.
@abkrim, my solution was one of these:
-
setting
title
value in English in config filel5-swagger.php
; -
setting
mbstring.func_overload=0
in PHP .ini files.
try add the below config to NginX server config
charset utf-8;
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 :)
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
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
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
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.