Uncaught SyntaxError: Unexpected token < in js scripts

🐛 bug report

I’ve a project with vanilla javascript,jquery and I’m migrating these to parcel for modularize,minify the JS and compile the sass, my project compiles ok and builds ok, but if I run this with the include local server (parcel index.html –public-url .), I get these errors

Uncaught SyntaxError: Unexpected token <   Chart.min.860861de.js:2 
Uncaught SyntaxError: Unexpected token <  detail.js:2 
Uncaught SyntaxError: Unexpected token < jquery.min.e6405add.js:2 
Uncaught SyntaxError: Unexpected token < ...

if I click inside some of these JS files, show the main html, so seems than parcel is taking the html as the body for my JS files

also external dependency files like jquery are not working (but when I build the project works fine)

I’m using jquery not modularized (not npm) instead requering the file

<script type="text/javascript" src="./assets/vendors/jquery.min.js"></script>

when I build the project with parcel build or parcel watch works but with the live server I get undefined $

🎛 Configuration (.babelrc, package.json, cli command)

I’m not using any particular babelrc config and I’m running this cli command
parcel watch index.html –public-url .

🤔 Expected Behavior

must show the website exactly as the build command shows…also if I run parcel watch arguments and compile the files and run these in my local server works, only fails with the include server

😯 Current Behavior

not show the website style and get many errors, also included jquery with

web.config.1bc228ac.js?v=2018:2 Uncaught SyntaxError: Unexpected token <
charting_library.min.d2f40bef.js:2 Uncaught SyntaxError: Unexpected token <
config.0874d187.js:2 Uncaught SyntaxError: Unexpected token <
init.17d1caca.js:2 Uncaught SyntaxError: Unexpected token <
estilo_sin_migrar.7374a674.js:2 Uncaught SyntaxError: Unexpected token <
Chart.min.860861de.js:2 Uncaught SyntaxError: Unexpected token <
detail.js:2 Uncaught SyntaxError: Unexpected token <
jquery.min.e6405add.js:2 Uncaught SyntaxError: Unexpected token <
jquery-ui.js:14 Uncaught ReferenceError: jQuery is not defined
    at jquery-ui.js:14
    at jquery-ui.js:16
(anonymous) @ jquery-ui.js:14
(anonymous) @ jquery-ui.js:16
Chart.min.4fe441d4.js:2 Uncaught SyntaxError: Unexpected token <
jquery.dataTables.js:56 Uncaught ReferenceError: jQuery is not defined
    at jquery.dataTables.js:56
    at jquery.dataTables.js:59

🌍 Your Environment

Software Version(s)
Parcel 1.11.0
Node v11.14.0
npm/Yarn 6.9.0
Operating System arch

1 possible answer(s) on “Uncaught SyntaxError: Unexpected token < in js scripts

  1. This error Uncaught SyntaxError: Unexpected token < is usually thrown because a Javascript file was requested from the dev server that does not exist and therefore Parcel serves index.html (beginning with <html causing the error).

    Could you provide your code or some smaller example where this happens?