Fix datatables_css or datatables_js not found or failed to open stream

Laravel
September 29, 20162 minutesuserMitul Golakiya
Fix datatables_css or datatables_js not found or failed to open stream

Recently, we introduced some breaking updates by which many developers are getting something from the following errors:

  • datatables_css.stub failed to open stream
  • datatables_js.stub failed to open stream
  • View [datatables_css] not found
  • View [datatables_js] not found

Problem:

so, the purpose of this breaking update was, till now when we generate CRUD with datatables we were including datatable scripts into table.blade.php something like the following:

{!! $dataTable->table(['width' => '100%']) !!}
@section('scripts')
    <link rel="stylesheet" href="https://cdn.datatables.net/buttons/1.0.3/css/buttons.dataTables.min.css">
    <script src="https://cdn.datatables.net/buttons/1.0.3/js/dataTables.buttons.min.js"></script>
    <script src="vendor/datatables/buttons.server-side.js"></script>
    {!! $dataTable->scripts() !!}
@endsection

And the main CSS files for datatables were included in the layout file layout/app.blade.php, also some js files were also included in the same folder. Like following,

<!-- Datatables -->
<script src="https://cdn.datatables.net/1.10.11/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.10.11/js/dataTables.bootstrap.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.2.1/js/dataTables.buttons.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.2.1/js/buttons.colVis.min.js"></script>

So the problem that we found was when we want to update the datatables version, we have to go to each file and update them manually. Also, there were some redundant JS and CSS files that were included in both table.blade.php & app.blade.php.

Solution:

As a solution, we decided to move these things to two partial files datatables_css.blade.php & datatables_js.blade.php. Which were published during the publishing layout.

php artisan infyom.publish:layout

so if anyone is getting this error then, run composer update to update your code to the latest commits and then try to run the above command and publish these two files into your layouts folder. As an alternative, you can also create those files manually from the templates and can update your layout file accordingly.

If anyone is still facing issues after performing these steps, then please post your comments below.