Manuel Soto
Manuel Soto
1,436 Points

Require is not defined.

I get an error in the browser after using php artisan serve. app.js:1 Uncaught ReferenceError: require is not defined at app.js:1

I'm assuming I need to launch it using yarn run dev or something similar, but it seems to be working just fine in the video using php artisan serve. Is there something I need to do so that require works when running php artisan serve?

So far the routes and views seem to be working fine the page changes when clicking the links and the url updates to what it should be (localhost:8000/tracks, localhost:8000/community, etc). What is not working is bootstrap.js with require('./bootstrap'). Clicking the links doesn't update the active class in the nav li. So pretty much it seems the js is not working with php artisan serve following along with this course. I'm not sure if this will become an issue later in the course, but any help resolving this would be appreciated. Thank you.

1 Answer

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 86,127 Points

It sounds like a problem with node.js. It might not be picking up the resource file properly.

The first thing I'd try is going to the root of your project and trying npm install in your terminal. Just to make sure the dependencies are properly installed. You might try this in the composer package manager for PHP as well since that is how it was set up in this course.

This sort of thing especially becomes a problem if you're working in different machines and have to clone projects in Git.