2

I have my notifications working locally, but once deployed to production, it's not showing anything in the console.

@pushonce('custom-scripts')
    <script>
        Echo.private('App.Models.User.' + @js($user->id)).notification((notification) => {
            console.log(notification); <---nothing printed in console on production.
            @this.call('addNotification', notification);
        });
    </script>
@endpushonce

If I open the console on production and type Echo it sees it, so I know Echo is imported or whatever.

My app is deployed on Laravel Forge. I've run the following commands on prod:

php artisan config:clear
php artisan cache:clear
composer dump-autoload
php artisan optimize:clear

Nothing seems to have any impact.

Also, I'm aware that Livewire has listeners for Echo, but this is the only way I was able to get things working locally.

UPDATE

I use Github actions for my CI/CD pipeline, and within my actions I'm running the following scripts, which I thought would be enough, but perhaps not:

      - uses: actions/checkout@main
      - name: Copy .env
        run: php -r "file_exists('.env') || copy('.env.example', '.env');"
      - name: Install Dependencies
        run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress
      - name: Generate key
        run: php artisan key:generate
      - name: Directory Permissions
        run: chmod -R 777 storage bootstrap/cache
      - name: Install dependencies
        run: npm install
      - name: Compile assets
        run: npm run production
      - name: Execute tests (Unit and Feature tests) via PHPUnit
        run: vendor/bin/phpunit

I thought I would post my build scripts as I don't think I've ever really paid much attention to them, and I'm not sure if they're set up right. I also don't have an npm run build script, and don't know what I would put in it:

 "scripts": {
        "dev": "npm run development",
        "development": "mix",
        "watch": "mix watch",
        "watch-poll": "mix watch -- --watch-options-poll=1000",
        "hot": "mix watch --hot",
        "prod": "npm run production",
        "production": "mix --production"
    },

UPDATE:

I ran npm run prod and npm run production locally, which theoretically should produce the same bundle I'm seeing in production, and I got the same result locally, i.e. I'm seeing the notification logged to the console. So it doesn't appear to be related to my build script.

Also, Echo is making it into the production build because I can call it from the console in production. So there has to be some other reason why it's not working.

hyphen
  • 2,368
  • 5
  • 28
  • 59

1 Answers1

1

Echo is a JS lib and i suggest that you have to build your scripts before you deploy. If your build your javascript in your pipeline make sure that your pipeline run the npm build command.

Add this to your Laravel Forge deployment script:

npm ci
npm run build
Maik Lowrey
  • 15,957
  • 6
  • 40
  • 79