Custom javascript in admin with bud.js

hello folks,

trying to add a custom javascript to perform Ajax parsing in the admin backend.

setup.php

add_action('admin_enqueue_scripts', function () {
    $wp = array(
        'env' => env('WP_ENV'),
        'ajaxUrl' => admin_url('admin-ajax.php'),
        'security' => Ajax::getNonce(),
    );
    wp_scripts()->add_data('jquery', 'group', 1);
    bundle('amazon-parser')->enqueueJs(true, ['jquery'])->localize('wp', $wp);
}, 100);

bud.config.js

...
app
    .entry('amazon-parser', ['@scripts/admin/amazon-parser'])

admin/amazon-parser.js

import domReady from '@roots/sage/client/dom-ready';

domReady(async () => {
  console.log('Amazon parser script loaded.');
//more stuffs...
});

BUT…
even the JS is loaded (I can read the console log) the editor… EXPLODES :smiley:
(white screen of dead… with errors

TypeError: undefined is not an object (evaluating ‘wp.editPost.initializeEditor’)

and many more… like the injection of my new script is generating some sort of conflicts…)

any hint/advice?

EDIT:

correcting the way I was bundling:

add_action('enqueue_block_editor_assets', function () {
    bundle('editor')->enqueue();
}, 100);

add_action('admin_enqueue_scripts', function () {

    $wp = array(
        'env' => env('WP_ENV'),
        'ajaxUrl' => admin_url('admin-ajax.php'),
        'security' => Ajax::getNonce(),
    );

//HERE SOLVED PARTIALLY  
  bundle('amazonParser')->localize('wp', $wp)->enqueue();
}, 100);

now is including correctly.

the JS file, though, makes an AJAX call which it seems not to work correctly.

rather than replying a simple response… parses an entire page…

the AIAX.php file contains a test_ajax_call which normally works on the frontend…

copy-pasting the whole response, it is the ENTIRE backend :smiley:
how is it supposed to happen that a simple Ajax text call:

 public function testAjaxCall(): void
    {
        self::checkAjaxReferer();
        wp_send_json(array('response' => 'Ok! AJAX works'));
        die();
    }

responds with the entire screen:

:point_down: