The Plugin Developer Handbook recommends using plugins_url()
to create the URL to the JS file. Try using that function inside your script loader, and using a different handle for the script depending on the context (like prefixing the admin script name with “admin-“) to avoid conflicting script registration.
Alternatively, you can register the script just once, and enqueue it when needed on the enqueue hooks.