Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

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
MOD
Jonathan Grieve
Treehouse Moderator 91,252 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.