0

I have added an amp-script to my amp page as described but I am getting the following error message when testing on localhost

[amp-script] Uncaught ReferenceError: eval is not defined
    at (amp-script%5Bsrc=%22http://localhost:8000/js/tolocaledate.js%22%5D.js:98)

Here is how I add the amp-script

The content of the script it self

const timeElm = document.querySelector('time');
const d = new Date(Date.parse(timeElm.innerText));
timeElm.innerText = d.toLocaleString(navigator.language || 'en-US', {
  day: 'numeric',
  month: 'short',
  year: 'numeric'
});

And how it is added to the HTML

<amp-script layout="container"
            src="{{ asset('/js/tolocaledate.js') }}">
            <time class="blog-post--time"
              datetime="{{ $post->online_at }}">
              2020-06-07 09:53:46
            </time>
          </amp-script>

I am trying to localise the date I am getting from the backend. I get the eval() is used to execute JS loaded async, but I don't get why I am getting a reference error. Here is the documentation I have been following https://amp.dev/documentation/examples/components/amp-script/?format=websites

kristian nissen
  • 2,809
  • 5
  • 44
  • 68

0 Answers0