Skip to content

Uncaught ReferenceError: route is not defined #482

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
TechhDan opened this issue Nov 20, 2020 · 15 comments · Fixed by #485
Closed

Uncaught ReferenceError: route is not defined #482

TechhDan opened this issue Nov 20, 2020 · 15 comments · Fixed by #485
Labels

Comments

@TechhDan
Copy link

TechhDan commented Nov 20, 2020

  • Jetstream Version: 1.6.1
  • Jetstream Stack: Inertia
  • Laravel Version: 8.15.0
  • PHP Version: 7.4.12
  • Database Driver & Version: mysql v8.0.20

Description: Login page displays error on the web console. This message disappears once a user is logged in.
Uncaught ReferenceError: route is not defined at Module../resources/js/app.js

Steps To Reproduce:

  1. laravel new sample
  2. composer require laravel/jetstream
  3. php artisan jetstream:install inertia (or with --teams)
  4. npm install && npm run dev
  5. php artisan migrate
  6. php artisan serve
  7. Visit Login, Registration, or Forgot Password page to view error on console.

UncaughtReferenceErrorRoute

@driesvints
Copy link
Member

What version of laravel-jetstream in your package.json are you using?

@TechhDan
Copy link
Author

I'm using laravel-jetstream version 0.0.3

@andreliem
Copy link

Having same issue as well, same versions.

@andreliem
Copy link

But I don't have the issue on another app with a older version

  "inertiajs/inertia-laravel": "^0.2.4",
  "laravel/jetstream": "^1.5",
    "laravel-jetstream": "^0.0.3",

@philmmoore
Copy link

I had this issue myself when installing Jetstream with Inertia for the first time where there were a few hiccups along the way i.e. the installer didn't work as expected because of my local environment so I had to install a few dependencies manually.

For me once I'd created an account and was taken to /dashboard the issue was clearer since I could only see @routes output in the browser. This is because the @routes blade directive wasn't available from the tightenco/ziggy and should've been added by the installer (but it wasn't because of those hiccups)

$this->requireComposerPackages('inertiajs/inertia-laravel:^0.2.4', 'laravel/sanctum:^2.6', 'tightenco/ziggy:^0.9.4');

If that's the same for you just do composer require tightenco/ziggy and it should resolve your issue.

@rokde
Copy link

rokde commented Nov 21, 2020

And the calls to route('logout').url() are wrong. There is no object you can call .url() at. Just remove and you are fine. It is in multiple Stub Templates in Jetstream wrong. So replace all occurrences to get it back to work.

@TechhDan
Copy link
Author

The Laravel Jetstream login, two-factor login, registration, password reset, and email verification views have guest.blade.php as the base layout while everything else uses app.blade.php. In the guest.blade.php the @routes directive is missing but the mix('js/app.js') depends on it. I tried adding it to the guest.blade.php template but now i get a TypeError
MissingRoutesDirective
CannotReadPropertyOfNull

@dinoluck
Copy link

dinoluck commented Nov 21, 2020

I'm getting the route is not defined on a fresh install of Laravel/Jetstream/Inertia/Vue stack when I go to /login
Steps to reproduce are the same as OP.

@bricehartmann
Copy link

bricehartmann commented Nov 21, 2020

On a fresh install of Laravel/Jetstream/Inertia I removed the following from resources/views/layouts/guest.blade.php

<!-- Scripts -->
<script src="{{ mix('js/app.js') }}" defer></script>

If I understand correctly, because all the Jetstream auth scaffolding is in blade (with livewire I think?), the application scripts are not necessary for guest views.

This resolved the error but I'm eager to learn about any other solution someone may have, I'm not sure if the application scripts should be included in guest views or not.

@nbs
Copy link

nbs commented Nov 23, 2020

I had all the same problems described above on a fresh installation.

I was able to fix it by changing the branch to "master" in composer.json.

"laravel/jetstream": "master",

And repeating the installation steps. The 1.6 release seems broken.

@driesvints
Copy link
Member

Managed to reproduce this. Investigating.

@driesvints
Copy link
Member

This should fix it: #485

@TechhDan
Copy link
Author

This should fix it: #485

Thank you!

@phoenixg
Copy link

phoenixg commented Jan 4, 2021

I meet the same issue, wonder how fix?

@tamodaleko
Copy link

@phoenixg Try running npm run production

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants