PiotrDabkowski / Js2Py

JavaScript to Python Translator & JavaScript interpreter written in 100% pure Python🚀 Try it online:
http://piter.io/projects/js2py
MIT License
2.48k stars 260 forks source link

Trying to import ws #246

Open OwOchle opened 3 years ago

OwOchle commented 3 years ago

Hello, I'm trying to import the ws module by doing this : js2py.require('ws') and it stops while printing:

La syntaxe du nom de fichier, de r�pertoire ou de volume est incorrecte.
Traceback (most recent call last):
  File "F:\Python\OWOP.py\main.py", line 3, in <module>
    js2py.require('ws')
  File "C:\Users\romeo\AppData\Local\Programs\Python\Python39\lib\site-packages\js2py\node_import.py", line 154, in require
    py_code = _get_and_translate_npm_module(module_name, include_polyfill=include_polyfill, update=update,
  File "C:\Users\romeo\AppData\Local\Programs\Python\Python39\lib\site-packages\js2py\node_import.py", line 95, in _get_and_translate_npm_module
    assert subprocess.call(
AssertionError: Could not install the required module: ws

Idk how to fix this

OwOchle commented 3 years ago

Update, i tweaked some things, so now the error is :

C:\Users\romeo\node_modules\babel-core\lib\transformation\file\index.js:558
      throw err;
      ^

SyntaxError: unknown: Unexpected token (318:1)
  316 | 
  317 | const proto = Object.defineProperties(() => {}, {
> 318 |     ...styles,
      |     ^
  319 |     level: {
  320 |         enumerable: true,
  321 |         get() {
    at Parser.pp$5.raise (C:\Users\romeo\node_modules\babylon\lib\index.js:4454:13)
    at Parser.pp.unexpected (C:\Users\romeo\node_modules\babylon\lib\index.js:1761:8)
    at Parser.pp$3.parseIdentifier (C:\Users\romeo\node_modules\babylon\lib\index.js:4332:10)
    at Parser.pp$3.parsePropertyName (C:\Users\romeo\node_modules\babylon\lib\index.js:4156:96)
    at Parser.pp$3.parseObj (C:\Users\romeo\node_modules\babylon\lib\index.js:4045:12)
    at Parser.pp$3.parseExprAtom (C:\Users\romeo\node_modules\babylon\lib\index.js:3719:19)
    at Parser.pp$3.parseExprSubscripts (C:\Users\romeo\node_modules\babylon\lib\index.js:3494:19)
    at Parser.pp$3.parseMaybeUnary (C:\Users\romeo\node_modules\babylon\lib\index.js:3474:19)
    at Parser.pp$3.parseExprOps (C:\Users\romeo\node_modules\babylon\lib\index.js:3404:19)
    at Parser.pp$3.parseMaybeConditional (C:\Users\romeo\node_modules\babylon\lib\index.js:3381:19) {
  pos: 9067,
  loc: Position { line: 318, column: 1 },
  _babel: true,
  codeFrame: '  316 | \n' +
    '  317 | const proto = Object.defineProperties(() => {}, {\n' +
    '> 318 | \t...styles,\n' +
    '      | \t^\n' +
    '  319 | \tlevel: {\n' +
    '  320 | \t\tenumerable: true,\n' +
    '  321 | \t\tget() {'
}
Traceback (most recent call last):
  File "F:\Python\OWOP.py\main.py", line 4, in <module>
    js2py.require('chalk')
  File "C:\Users\romeo\AppData\Local\Programs\Python\Python39\lib\site-packages\js2py\node_import.py", line 154, in require
    py_code = _get_and_translate_npm_module(module_name, include_polyfill=include_polyfill, update=update,
  File "C:\Users\romeo\AppData\Local\Programs\Python\Python39\lib\site-packages\js2py\node_import.py", line 102, in _get_and_translate_npm_module
    assert subprocess.call(
AssertionError: Error when converting module to the js bundle

Process finished with exit code 1
OwOchle commented 3 years ago

Update again, the problem is that my module is in JS6, so that's why, i think

OwOchle commented 3 years ago

error :

C:\Users\romeo\node_modules\babel-core\lib\transformation\file\index.js:558
      throw err;
      ^

SyntaxError: unknown: Unexpected token (8700:16)
  8698 | 
  8699 | class Client {
> 8700 |     static RANK = {
       |                 ^
  8701 |             ADMIN: 3,
  8702 |             MODERATOR: 2,
  8703 |             USER: 1,
    at Parser.pp$5.raise (C:\Users\romeo\node_modules\babylon\lib\index.js:4454:13)
    at Parser.pp.unexpected (C:\Users\romeo\node_modules\babylon\lib\index.js:1761:8)
    at Parser.pp$1.parseClassProperty (C:\Users\romeo\node_modules\babylon\lib\index.js:2571:50)
    at Parser.pp$1.parseClassBody (C:\Users\romeo\node_modules\babylon\lib\index.js:2516:34)
    at Parser.pp$1.parseClass (C:\Users\romeo\node_modules\babylon\lib\index.js:2406:8)
    at Parser.pp$1.parseStatement (C:\Users\romeo\node_modules\babylon\lib\index.js:1843:19)
    at Parser.pp$1.parseBlockBody (C:\Users\romeo\node_modules\babylon\lib\index.js:2268:21)
    at Parser.pp$1.parseBlock (C:\Users\romeo\node_modules\babylon\lib\index.js:2247:8)
    at Parser.pp$3.parseFunctionBody (C:\Users\romeo\node_modules\babylon\lib\index.js:4235:22)
    at Parser.pp$1.parseFunction (C:\Users\romeo\node_modules\babylon\lib\index.js:2386:8) {
  pos: 304716,
  loc: Position { line: 8700, column: 16 },
  _babel: true,
  codeFrame: '  8698 | \n' +
    '  8699 | class Client {\n' +
    '> 8700 |     static RANK = {\n' +
    '       |                 ^\n' +
    '  8701 |             ADMIN: 3,\n' +
    '  8702 |             MODERATOR: 2,\n' +
    '  8703 |             USER: 1,'
}
Traceback (most recent call last):
  File "F:\Python\OWOP.py\main.py", line 3, in <module>
    js2py.require('owop-js')
  File "C:\Users\romeo\AppData\Local\Programs\Python\Python39\lib\site-packages\js2py\node_import.py", line 154, in require
    py_code = _get_and_translate_npm_module(module_name, include_polyfill=include_polyfill, update=update,
  File "C:\Users\romeo\AppData\Local\Programs\Python\Python39\lib\site-packages\js2py\node_import.py", line 102, in _get_and_translate_npm_module
    assert subprocess.call(
AssertionError: Error when converting module to the js bundle
vk765 commented 3 years ago

II have a similar problem, but with another stacktrace:

Traceback (most recent call last):
  File "/Users/vkornieiev/aqa/tests/_helpers/websocket_js.py", line 4, in <module>
    js2py.require('ws')
  File "/Users/vkornieiev/aqa/venv/lib/python3.8/site-packages/js2py/node_import.py", line 166, in require
    exec(py_code, context)
  File "<string>", line 11266, in <module>
  File "<string>", line 11265, in PyJs_LONG_1055_
  File "/Users/vkornieiev/aqa/venv/lib/python3.8/site-packages/js2py/base.py", line 949, in __call__
    return self.call(self.GlobalObject, args)
  File "/Users/vkornieiev/aqa/venv/lib/python3.8/site-packages/js2py/base.py", line 1464, in call
    return Js(self.code(*args))
  File "<string>", line 11256, in PyJsHoisted_r_
  File "/Users/vkornieiev/aqa/venv/lib/python3.8/site-packages/js2py/base.py", line 949, in __call__
    return self.call(self.GlobalObject, args)
  File "/Users/vkornieiev/aqa/venv/lib/python3.8/site-packages/js2py/base.py", line 1464, in call
    return Js(self.code(*args))
  File "<string>", line 11246, in PyJsHoisted_o_
  File "/Users/vkornieiev/aqa/venv/lib/python3.8/site-packages/js2py/base.py", line 996, in callprop
    return cand.call(self, args)
  File "/Users/vkornieiev/aqa/venv/lib/python3.8/site-packages/js2py/base.py", line 1464, in call
    return Js(self.code(*args))
  File "/Users/vkornieiev/aqa/venv/lib/python3.8/site-packages/js2py/prototypes/jsfunction.py", line 27, in call
    return this.call(obj, args)
  File "/Users/vkornieiev/aqa/venv/lib/python3.8/site-packages/js2py/base.py", line 1464, in call
    return Js(self.code(*args))
  File "<string>", line 54, in PyJs_anonymous_2_
  File "/Users/vkornieiev/aqa/venv/lib/python3.8/site-packages/js2py/base.py", line 949, in __call__
    return self.call(self.GlobalObject, args)
  File "/Users/vkornieiev/aqa/venv/lib/python3.8/site-packages/js2py/base.py", line 1464, in call
    return Js(self.code(*args))
  File "<string>", line 11244, in PyJs_anonymous_1054_
  File "/Users/vkornieiev/aqa/venv/lib/python3.8/site-packages/js2py/base.py", line 949, in __call__
    return self.call(self.GlobalObject, args)
  File "/Users/vkornieiev/aqa/venv/lib/python3.8/site-packages/js2py/base.py", line 1464, in call
    return Js(self.code(*args))
  File "<string>", line 11246, in PyJsHoisted_o_
  File "/Users/vkornieiev/aqa/venv/lib/python3.8/site-packages/js2py/base.py", line 996, in callprop
    return cand.call(self, args)
  File "/Users/vkornieiev/aqa/venv/lib/python3.8/site-packages/js2py/base.py", line 1464, in call
    return Js(self.code(*args))
  File "/Users/vkornieiev/aqa/venv/lib/python3.8/site-packages/js2py/prototypes/jsfunction.py", line 27, in call
    return this.call(obj, args)
  File "/Users/vkornieiev/aqa/venv/lib/python3.8/site-packages/js2py/base.py", line 1464, in call
    return Js(self.code(*args))
  File "<string>", line 99, in PyJs_anonymous_3_
  File "/Users/vkornieiev/aqa/venv/lib/python3.8/site-packages/js2py/base.py", line 996, in callprop
    return cand.call(self, args)
  File "/Users/vkornieiev/aqa/venv/lib/python3.8/site-packages/js2py/base.py", line 1464, in call
    return Js(self.code(*args))
  File "/Users/vkornieiev/aqa/venv/lib/python3.8/site-packages/js2py/prototypes/jsfunction.py", line 27, in call
    return this.call(obj, args)
  File "/Users/vkornieiev/aqa/venv/lib/python3.8/site-packages/js2py/base.py", line 1464, in call
    return Js(self.code(*args))
  File "<string>", line 97, in PyJs_anonymous_4_
  File "/Users/vkornieiev/aqa/venv/lib/python3.8/site-packages/js2py/base.py", line 996, in callprop
    return cand.call(self, args)
  File "/Users/vkornieiev/aqa/venv/lib/python3.8/site-packages/js2py/base.py", line 1464, in call
    return Js(self.code(*args))
  File "/Users/vkornieiev/aqa/venv/lib/python3.8/site-packages/js2py/prototypes/jsfunction.py", line 27, in call
    return this.call(obj, args)
  File "/Users/vkornieiev/aqa/venv/lib/python3.8/site-packages/js2py/base.py", line 1464, in call
    return Js(self.code(*args))
  File "<string>", line 78, in PyJs_anonymous_5_
  File "/Users/vkornieiev/aqa/venv/lib/python3.8/site-packages/js2py/base.py", line 949, in __call__
    return self.call(self.GlobalObject, args)
  File "/Users/vkornieiev/aqa/venv/lib/python3.8/site-packages/js2py/base.py", line 1464, in call
    return Js(self.code(*args))
  File "<string>", line 11244, in PyJs_anonymous_1054_
  File "/Users/vkornieiev/aqa/venv/lib/python3.8/site-packages/js2py/base.py", line 949, in __call__
    return self.call(self.GlobalObject, args)
  File "/Users/vkornieiev/aqa/venv/lib/python3.8/site-packages/js2py/base.py", line 1464, in call
    return Js(self.code(*args))
  File "<string>", line 11246, in PyJsHoisted_o_
  File "/Users/vkornieiev/aqa/venv/lib/python3.8/site-packages/js2py/base.py", line 996, in callprop
    return cand.call(self, args)
  File "/Users/vkornieiev/aqa/venv/lib/python3.8/site-packages/js2py/base.py", line 1464, in call
    return Js(self.code(*args))
  File "/Users/vkornieiev/aqa/venv/lib/python3.8/site-packages/js2py/prototypes/jsfunction.py", line 27, in call
    return this.call(obj, args)
  File "/Users/vkornieiev/aqa/venv/lib/python3.8/site-packages/js2py/base.py", line 1464, in call
    return Js(self.code(*args))
  File "<string>", line 11118, in PyJs_anonymous_1050_
  File "/Users/vkornieiev/aqa/venv/lib/python3.8/site-packages/js2py/base.py", line 949, in __call__
    return self.call(self.GlobalObject, args)
  File "/Users/vkornieiev/aqa/venv/lib/python3.8/site-packages/js2py/base.py", line 1464, in call
    return Js(self.code(*args))
  File "<string>", line 11244, in PyJs_anonymous_1054_
  File "/Users/vkornieiev/aqa/venv/lib/python3.8/site-packages/js2py/base.py", line 949, in __call__
    return self.call(self.GlobalObject, args)
  File "/Users/vkornieiev/aqa/venv/lib/python3.8/site-packages/js2py/base.py", line 1464, in call
    return Js(self.code(*args))
  File "<string>", line 11246, in PyJsHoisted_o_
  File "/Users/vkornieiev/aqa/venv/lib/python3.8/site-packages/js2py/base.py", line 996, in callprop
    return cand.call(self, args)
  File "/Users/vkornieiev/aqa/venv/lib/python3.8/site-packages/js2py/base.py", line 1464, in call
    return Js(self.code(*args))
  File "/Users/vkornieiev/aqa/venv/lib/python3.8/site-packages/js2py/prototypes/jsfunction.py", line 27, in call
    return this.call(obj, args)
  File "/Users/vkornieiev/aqa/venv/lib/python3.8/site-packages/js2py/base.py", line 1464, in call
    return Js(self.code(*args))
  File "<string>", line 9492, in PyJs_anonymous_884_
  File "/Users/vkornieiev/aqa/venv/lib/python3.8/site-packages/js2py/base.py", line 949, in __call__
    return self.call(self.GlobalObject, args)
  File "/Users/vkornieiev/aqa/venv/lib/python3.8/site-packages/js2py/base.py", line 1464, in call
    return Js(self.code(*args))
  File "<string>", line 11244, in PyJs_anonymous_1054_
  File "/Users/vkornieiev/aqa/venv/lib/python3.8/site-packages/js2py/base.py", line 949, in __call__
    return self.call(self.GlobalObject, args)
  File "/Users/vkornieiev/aqa/venv/lib/python3.8/site-packages/js2py/base.py", line 1464, in call
    return Js(self.code(*args))
  File "<string>", line 11246, in PyJsHoisted_o_
  File "/Users/vkornieiev/aqa/venv/lib/python3.8/site-packages/js2py/base.py", line 996, in callprop
    return cand.call(self, args)
  File "/Users/vkornieiev/aqa/venv/lib/python3.8/site-packages/js2py/base.py", line 1464, in call
    return Js(self.code(*args))
  File "/Users/vkornieiev/aqa/venv/lib/python3.8/site-packages/js2py/prototypes/jsfunction.py", line 27, in call
    return this.call(obj, args)
  File "/Users/vkornieiev/aqa/venv/lib/python3.8/site-packages/js2py/base.py", line 1464, in call
    return Js(self.code(*args))
  File "<string>", line 4553, in PyJs_anonymous_403_
  File "/Users/vkornieiev/aqa/venv/lib/python3.8/site-packages/js2py/base.py", line 949, in __call__
    return self.call(self.GlobalObject, args)
  File "/Users/vkornieiev/aqa/venv/lib/python3.8/site-packages/js2py/base.py", line 1464, in call
    return Js(self.code(*args))
  File "<string>", line 2006, in PyJs_anonymous_157_
  File "/Users/vkornieiev/aqa/venv/lib/python3.8/site-packages/js2py/base.py", line 949, in __call__
    return self.call(self.GlobalObject, args)
  File "/Users/vkornieiev/aqa/venv/lib/python3.8/site-packages/js2py/base.py", line 1464, in call
    return Js(self.code(*args))
  File "<string>", line 4551, in PyJs_anonymous_405_
  File "/Users/vkornieiev/aqa/venv/lib/python3.8/site-packages/js2py/base.py", line 949, in __call__
    return self.call(self.GlobalObject, args)
  File "/Users/vkornieiev/aqa/venv/lib/python3.8/site-packages/js2py/base.py", line 1464, in call
    return Js(self.code(*args))
  File "/Users/vkornieiev/aqa/venv/lib/python3.8/site-packages/js2py/constructors/jsuint16array.py", line 32, in Uint16Array
    temp = Js(numpy.array(array, dtype=numpy.uint16))
NameError: name 'numpy' is not defined
Talal916 commented 3 years ago

@vk765 I don't think your issue is similar. Just run npm install numpy in your environment.