2

I have an application that uses brunch, chaplin, and coffeescript for the front end. Brunch builds the application without any errors. However, when I do brunch watch --serverand navigate to http://localhost:3333, an error is generated and the page never loads.

This was previously working just fine. diff shows no changes in the repository that would account for the change in behavior. I also checked out previous versions of the front end code from when I know the dev. server was working, but they all give the same error. I tried deleting the built code and completely rebuilding, but that didn't help either.

I am thinking it must be something I did in an untracked file, but for the life of me, I can't find it. Here is the output of the chrome error message:

Resource interpreted as Stylesheet but transferred with MIME type text/html:       "http://localhost:3333/pub/css/app.css". localhost/:10
Resource interpreted as Script but transferred with MIME type text/html: "http://localhost:3333/pub/js/vendor.js". localhost/:11
Resource interpreted as Script but transferred with MIME type text/html: "http://localhost:3333/pub/js/app.js". localhost/:20
Uncaught SyntaxError: Unexpected token < vendor.js:1
Uncaught SyntaxError: Unexpected token < app.js:1
Uncaught ReferenceError: require is not defined (index):21
(anonymous function) (index):21

The offending line in index appears to be

<script>require('initialize');</script>

This line is unchanged from other similarly configured projects that work perfectly. I assume it is probably something dumb, but it is just vague enough that web search hasn't helped much. Hopefully someone else has come across this.

What can I do do diagnose the problem or fix this?

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
crlane
  • 521
  • 5
  • 16
  • Did you find the solution for this problem? – Benidorm Jan 23 '20 at 13:38
  • @Benidorm unfortunately I don't think I did - I must have found a workaround or something. Sadly, it is from so long ago that I don't remember the particulars. – crlane Jan 23 '20 at 21:39

1 Answers1

2

You have to confirm, but I believe you are getting 404 errors on your JavaScript and Stylesheets, so they are returning HTML pages that describe the 404 error. That's why that line of JavaScript is erroring out - it depends on code in app.js, which is not being loaded.

Make sure the paths are correct, i.e. point your browser to http://localhost:3333/pub/css/app.css and confirm that you get a CSS file and not a 404 from your web server. If you get a 404, that means you have to update the href for the CSS and the src for the JS, or make sure Brunch is placing the files where they are supposed to be.

Michal
  • 2,532
  • 1
  • 19
  • 27
  • Thank you for the answer, but unfortunately they are not giving 404s. But for some reason the server is interpreting seeing app.css and app.js as html. In fact, both documents return the document at app/assets/index.html. Obviously I inadvertently changed some configuration, and I'll keep looking. To make things even less clear, the code works when run with the full application. – crlane Feb 17 '14 at 14:41
  • Do you have a wildcard route defined on your Backbone Router? It might be catching those requests and shoving them off to index. – Michal Feb 17 '14 at 22:34