Js2Py icon indicating copy to clipboard operation
Js2Py copied to clipboard

Error when importing npm package 'serverless'

Open giusepperaffa opened this issue 3 years ago • 0 comments

I have been trying to execute with Js2Py a simplified version of this JavaScript code, but the line const Serverless = require('serverless'); is causing a problem.

Configuration Python 3.8.10 npm version 8.5.5 node version v16.15.0 Ubuntu Linux 20.04

Attempts I have attempted to import the serverless package in two ways. In both cases, I ran my code within a Python virtual environment, i.e., I have activated the environment, started the Python interpreter and imported Js2Py.

  1. The section Limitations says You can try it yourself by importing any supported npm package via js2py.require('your_package'). So I tried the following:
js2py.require('serverless')
  1. Taking into account this example and the explanation on JS context provided here, I tried the following:
import js2py
ctx = js2py.EvalJs(enable_require=True)
ctx.execute("const Serverless = require('serverless');")

Linux Shell Log In both cases, the problem seems to be a missing file. The most important sections of the Linux Shell Log should be the following:

Run `npm audit` for details.
[Error: Can't walk dependency graph: ENOENT: no such file or directory, lstat '/tmp/tmptb47y5aq/worker_threads'
    required by /tmp/tmptb47y5aq/node_modules/write-file-atomic/lib/index.js] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'lstat',
  path: '/tmp/tmptb47y5aq/worker_threads',
Error: Error: Can't walk dependency graph: ENOENT: no such file or directory, lstat '/tmp/tmptb47y5aq/worker_threads'
    required by /tmp/tmptb47y5aq/node_modules/write-file-atomic/lib/index.js
    at Readable.<anonymous> ([eval]:1:126)
    at Readable.emit (node:events:527:28)
    at Labeled.<anonymous> (/tmp/tmptb47y5aq/node_modules/read-only-stream/index.js:28:44)
    at Labeled.emit (node:events:527:28)
    at Labeled.<anonymous> (/tmp/tmptb47y5aq/node_modules/stream-splicer/index.js:130:18)
    at Labeled.emit (node:events:527:28)
    at Deps.<anonymous> (/tmp/tmptb47y5aq/node_modules/stream-splicer/index.js:130:18)
    at Deps.emit (node:events:527:28)
    at /tmp/tmptb47y5aq/node_modules/module-deps/index.js:387:25
    at onresolve (/tmp/tmptb47y5aq/node_modules/module-deps/index.js:185:25)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/giuseppe/Desktop/serverless-framework-parser/venv/lib/python3.8/site-packages/js2py/evaljs.py", line 199, in execute
    exec (compiled, self._context)
  File "<EvalJS snippet>", line 2, in <module>
  File "/home/giuseppe/Desktop/serverless-framework-parser/venv/lib/python3.8/site-packages/js2py/base.py", line 949, in __call__
    return self.call(self.GlobalObject, args)
  File "/home/giuseppe/Desktop/serverless-framework-parser/venv/lib/python3.8/site-packages/js2py/base.py", line 1464, in call
    return Js(self.code(*args))
  File "/home/giuseppe/Desktop/serverless-framework-parser/venv/lib/python3.8/site-packages/js2py/evaljs.py", line 162, in _js_require_impl
    return require(to_python(npm_module_name), context=self._context)
  File "/home/giuseppe/Desktop/serverless-framework-parser/venv/lib/python3.8/site-packages/js2py/node_import.py", line 155, in require
    py_code = _get_and_translate_npm_module(module_name, include_polyfill=include_polyfill, update=update,
  File "/home/giuseppe/Desktop/serverless-framework-parser/venv/lib/python3.8/site-packages/js2py/node_import.py", line 103, in _get_and_translate_npm_module
    assert subprocess.call(
AssertionError: Error when converting module to the js bundle

Questions

  • Is the package 'serverless' supported by Js2Py?
  • Is it possible that working within a virtual environment is causing the issue?
  • Where can I find a list of all npm packages supported by Js2Py?

Any help would be greatly appreciated. Thank you very much.

giusepperaffa avatar Sep 05 '22 11:09 giusepperaffa