sintaxi / surge

CLI for the surge.sh CDN
https://surge.sh
2.84k stars 135 forks source link

Getting `Uncaught SyntaxError: Unexpected token '<'` on new static nuxtjs app #420

Closed danieledler closed 3 years ago

danieledler commented 3 years ago

I have a static site generated with nuxt but after the upgrade from nuxt 2.10.2 to 2.14.1 it stopped render on surge.sh. When the browser gets _nuxt/node_modules/commons.[hash].js, the content is not from that .js file but from the main .html file, and hence the unexpected token < (see attached screenshot).

image

Steps to reproduce the error:

1. yarn create nuxt-app test-nuxt-app (select 'universal' mode and 'static' target) 
2. cd test-nuxt-app && yarn generate
3. surge dist

I have tried a couple of local servers and also a couple of cloud servers (netlify and commons.host) and they all work, so maybe there is something on the surge.sh servers that can be updated to fix this issue?

Thanks for any help!

sintaxi commented 3 years ago

Thanks for providing steps to reproduce. Very helpful!

Surge by default ignores the node_modules folder. You can fix this on your end by adding a .surgeignore file in the directory you upload to surge. Eg. echo '!node_modules' > dist/.surgeignore

danieledler commented 3 years ago

Thank you very much, that fixes this issue!

Nuxt is on their way with a fix to not create chunks in a node_modules subfolder: https://github.com/nuxt/nuxt.js/pull/7906.