Why my php script doesn’t process javascript script on localhost? [closed]

I have a php scrip which works fine, but for whatever reason it doesn’t process my javascript scripts. I tried to link it with the src attribute , it doesn’t work. I tried to require it with php inside the script:

<script>
<?php require 'path-to-js.script' ?>
</script>
  • it doesn’t work.
    It loads the javascript, so i can see it when i inspect the script element, but treats it like the code is not there.
<script>
js code is loaded, visible but doesn't do anything. Event listeners not registered. It acts like simple text which is not wrapped in <script> tags.
</script>

I have no idea what is the problem. I tried to empty my browser cache, nothing.

One thing to note, it seems to work on a live server, but not when i run it on localhost.
It alse works within an html file, so it is not the js script that’s faulty. It only produces the above problem when i try to use the script within a php file.

When i do the same with CSS, it works.
For example <link rel ...> or <style> <?php require 'pat-to-css' ?> </style> => success. When i try with my js => failure.

Any ideas?

Link the script file, require the script content, empty caches, nothing seems to work.