JSPyBridge icon indicating copy to clipboard operation
JSPyBridge copied to clipboard

Disable logging for babel require.

Open luanon404 opened this issue 1 year ago • 5 comments

Here is my error:

☕  JavaScript Error  Call to 'default' failed:  
> traverse(ast, {  
  at <module> (.../Playground/babel.py:13)  
>  

... across the bridge ...  

  at TraversalContext.visitSingle (.../@babel/traverse/lib/context.js:66:19)  
  at TraversalContext.visitQueue (.../@babel/traverse/lib/context.js:90:16)  
  at NodePath.visit (.../@babel/traverse/lib/path/context.js:95:52)  
  at traverseNode (.../@babel/traverse/lib/traverse-node.js:22:17)  
  at TraversalContext.visit (.../@babel/traverse/lib/context.js:113:19)  
  at TraversalContext.visitSingle (.../@babel/traverse/lib/context.js:66:19)  
  at TraversalContext.visitQueue (.../@babel/traverse/lib/context.js:90:16)  
  at NodePath.visit (.../@babel/traverse/lib/path/context.js:89:31)  
  at NodePath.call (.../@babel/traverse/lib/path/context.js:40:18)  
  at NodePath._call (.../@babel/traverse/lib/path/context.js:52:13)  

> throw new Error(`You appear to be using a plugin with an async traversal visitor, ` + `which your current version of Babel does not support. ` + `If you're using a published plugin, you may need to upgrade ` + `your @babel/core version.`);  

🌉 Error: You appear to be using a plugin with an async traversal visitor, which your current version of Babel does not support. If you're using a published plugin, you may need to upgrade your @babel/core version.  

if i use version="latest", i got:

☕  JavaScript Error  Call to 'require' failed:  
> traverse = require("@babel/traverse", version="latest").default  
  at <module> (.../Playground/babel.py:8)  
>  

... across the bridge ...  

  at Readable.push (node:internal/streams/readable:375:5)  
  at readableAddChunkPushByteMode (node:internal/streams/readable:495:3)  
  at addChunk (node:internal/streams/readable:545:12)  
  at Socket.emit (node:events:514:28)  
  at Socket.<anonymous> (.../javascript/js/bridge.js:292:18)  
  at Bridge.onMessage (.../javascript/js/bridge.js:231:25)  
  at Bridge.call (.../javascript/js/bridge.js:136:42)  
  at Object.$require [as require] (.../javascript/js/deps.js:128:22)  
  at PackageManager.install (.../javascript/js/deps.js:63:35)  
  at PackageManager.getInstalledVersion (.../javascript/js/deps.js:41:39)  
  **TypeError: Cannot read properties of undefined (reading '@babel/traverse')**  

🌉 **TypeError:** Cannot read properties of undefined (reading '@babel/traverse')  

or

☕  **JavaScript Error** Call to 'require' failed:  
> `traverse = require("@babel/traverse@latest").default`  
  at <module> (.../Playground/babel.py:8)  
>  

... across the bridge ...  

  at Readable.push (node:internal/streams/readable:375:5)  
  at readableAddChunkPushByteMode (node:internal/streams/readable:495:3)  
  at addChunk (node:internal/streams/readable:545:12)  
  at Socket.emit (node:events:514:28)  
  at Socket.<anonymous> (.../javascript/js/bridge.js:292:18)  
  at Bridge.onMessage (.../javascript/js/bridge.js:231:25)  
  at Bridge.call (.../javascript/js/bridge.js:136:42)  
  at Object.$require [as require] (.../javascript/js/deps.js:128:22)  
  at PackageManager.install (.../javascript/js/deps.js:63:35)  
  at PackageManager.getInstalledVersion (.../javascript/js/deps.js:41:39)  
  **TypeError: Cannot read properties of undefined (reading '@babel/traverse@latest')**  

🌉 **TypeError:** Cannot read properties of undefined (reading '@babel/traverse@latest')  

I have no problem with the code, but there is anyway to disable error for this call?

luanon404 avatar Dec 05 '24 07:12 luanon404

I advise you instead name the package something else when installing, as to avoid issues with JSPyBridge's parsing.

python -m javascript install babel-traverse@npm:@babel/traverse will allow you to require the package with just require('babel-traverse').

extremeheat avatar Dec 05 '24 08:12 extremeheat

I advise you instead name the package something else when installing, as to avoid issues with JSPyBridge's parsing.

python -m javascript install babel-traverse@npm:@babel/traverse will allow you to require the package with just require('babel-traverse').

thanks for response, i dont get it, the docs dont say anything about that, i will try later, hope its working, i will reply after testing

luanon404 avatar Dec 05 '24 09:12 luanon404

I advise you instead name the package something else when installing, as to avoid issues with JSPyBridge's parsing.

python -m javascript install babel-traverse@npm:@babel/traverse will allow you to require the package with just require('babel-traverse').

hi again, i tried, but i still got same error, i tested package with nodejs script, all good, so this maybe some mistake here, can you check about it?

luanon404 avatar Dec 05 '24 16:12 luanon404

that code still working if i put it in threading

threading.Thread(target=traverse, args=(ast, {
    "VariableDeclarator": collect_function_bodies,
}), daemon=True).start()

so this is only solution i know right now

luanon404 avatar Dec 05 '24 17:12 luanon404

or better that

def proxy_run(function, *args, **kwargs):
    try:
        return function(*args, **kwargs)
    except Exception:
        pass

luanon404 avatar Dec 05 '24 17:12 luanon404