AMP does not allow custom JavaScript to run in amp pages you can use amp-bind or you can exclude scripts and AMP does not support features that rely heavily on JavaScript like script tags, if you receive an error in search console you should fix this JavaScript error in amp pages or any amp error will not be indexed in search console some times and will see errorr message in search console.
First you need to perform live url inspection test in search console and check if google is seeing the error in real time, some times there can be bugs as well.
Use Valid AMP Script Tags
if you get custom javascript not allowed error then you need to use valid AMP Page and use amp script tags which will not trigger Javascript errors in AMP Pages and once you make changes then perform live url inspection in search console and this will not trigger error message.
Perform Live URL Inspection in Search Console
To perform live url in search console -> Grab the AMP error url and open search console and simple drop the url on top search bar and click enter and then it will fetch the page.
Now, click on Live test on the screen -> wait for google to check for errors in real time and if you are still seeing an error message then you need to fix the error.
Solution for Custom JavaScript Not Allowed in AMP Pages
Step 1: First you should know which script is added in your amp pages and to check you can validate your pages here https://validator.ampproject.org/ or you can check with chrome extension as well.
Step 2: Once you have figured out which script tag is causing this issue, you have to remove the scrip tag from amp.
Step 3: If you don’t want to remove script tag amp supports specific way of using amp JavaScript now, you can code if you really need them on your amp pages.
Note: Including scripts and java scripts in AMP pages will slow down AMP pages which is negative impact on AMP usage. Now google recommends fast loading pages and this is the main reason why publishers will be using AMP pages even though they have website only for fast loading and better performance on mobile devices.
Step 4: Once you have done removing script tag custom JavaScript not allowed in AMP pages will be fixed.
You can cross check with amp validator to confirm JavaScript error is fixed and you can submit amp pages error in search console for validation and fix, search console will identify and fix this issue as validation is successful.
WordPress Website Plugin
If you are using WordPress plugin like amp for WordPress or any other WordPress plugin for amp pages, now you can easily fix this issue. AMP for WordPress provides you an option of not executing amp scripts by including or excluding JavaScript in AMP pages in very easy way by adding CSS classes.
To exclude JavaScript and fix JavaScript now allowed in amp pages with custom css follow these steps:
Step 1: Open AMP for WordPress plugin
Step 2: Go to Design options
Step 3: Click on Global
Step 4: On right side panel scroll down
Step 5: At the bottom you can see Advanced options with custom CSS box.
Step 6: Navigate to NON-AMP version of website and find the class using debugging mode and enter the class name here in AMP box. It will not execute custom script tags, if it is mentioned here.
That’s it, once added navigate to amp page and validate your amp page, now you will not be seeing any custom JavaScript is not allowed in amp pages error. Since it is excluded to executed in WordPress amp pages.
W3 Total Cache WordPress Plugin
You can also fix this error by using w3 total cache plugin if you are using it on your WordPress website. Follow the below steps to fix custom JavaScript not allowed in amp.
Step 1: Go to performance in w3 total cache plugin.
Step 2: Now install AMP for WordPress default one.
Step 3: Once amp installed and activated then custom JavaScript will not execute in AMP pages.
Note: If any script tag is present then only custom JavaScript is not allowed in AMP pages error will be triggered in search console.
AMP is built for fast loading pages and if you use JavaScript and executing JavaScript in AMP pages will slow down AMP fast loading pages.
You can use if you want by not using script tag, you can use JavaScript by using amp-bind tag.
If you have script tag then only this error will trigger, do a inspect url in search console and debug which script tag is executing
You can visit amp Validator org website and check for errors and fix them or use search console live URL inspection tool both are same.