crlane
crlane

Reputation: 521

Brunch `require` not defined

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?

Upvotes: 2

Views: 1463

Answers (1)

Michal
Michal

Reputation: 2532

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.

Upvotes: 2

Related Questions