Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot import module @cortex-js/compute-engine #111

Open
edward1127 opened this issue Dec 12, 2023 · 8 comments
Open

Cannot import module @cortex-js/compute-engine #111

edward1127 opened this issue Dec 12, 2023 · 8 comments

Comments

@edward1127
Copy link

edward1127 commented Dec 12, 2023

Does anyone know how I can import module @cortex-js/compute-engine?

I get a module not found error when importing that module.

javascript.errors.JavaScriptError: ('require', "Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@cortex-js/compute-engine' imported from /home/edward/anaconda3/envs/arete/lib/python3.11/site-packages/javascript/js/deps.js\n    at new NodeError (node:internal/errors:399:5)\n    at packageResolve (node:internal/modules/esm/resolve:783:9)\n 
@extremeheat
Copy link
Owner

Seems to work ok for me

image

If nessesary, you can use the CLI tool to manually install the package with

python -m javascript --install @cortex-js/compute-engine

@edward1127
Copy link
Author

edward1127 commented Dec 13, 2023

thanks for replying. Yep, I confirmed that it works when using it independently. Then, it seems like this package and Django are not compatible.

django==4.2
djangorestframework==3.14.0

@extremeheat
Copy link
Owner

There does seem to be a minor issue with ESM path resolution, potentially fixed in #115. But with or without Django, I don't notice any issues.

without - https://gist.github.com/extremeheat/c97ea38e8fb40921080ad97e2325a5b1
with - https://gist.github.com/extremeheat/db89aedb8cfcd76d31fecd5631613477

@edward1127
Copy link
Author

edward1127 commented Dec 15, 2023

I believe if you start the Django server, you will see the error. I think it might have something to do with how Django handles the import path.

python manage.py runserver

Watching for file changes with StatReloader
2023-12-15 18:28:20,629 [INFO] django.utils.autoreload: Watching for file changes with StatReloader
Performing system checks...

Exception in thread django-main-thread:
Traceback (most recent call last):
  File "/home/edward/anaconda3/envs/arete/lib/python3.11/threading.py", line 1038, in _bootstrap_inner
    self.run()
  File "/home/edward/anaconda3/envs/arete/lib/python3.11/threading.py", line 975, in run
    self._target(*self._args, **self._kwargs)
  File "/home/edward/anaconda3/envs/arete/lib/python3.11/site-packages/django/utils/autoreload.py", line 64, in wrapper
    fn(*args, **kwargs)
  File "/home/edward/anaconda3/envs/arete/lib/python3.11/site-packages/django/core/management/commands/runserver.py", line 133, in inner_run
    self.check(display_num_errors=True)
  File "/home/edward/anaconda3/envs/arete/lib/python3.11/site-packages/django/core/management/base.py", line 485, in check
    all_issues = checks.run_checks(
                 ^^^^^^^^^^^^^^^^^^
  File "/home/edward/anaconda3/envs/arete/lib/python3.11/site-packages/django/core/checks/registry.py", line 88, in run_checks
    new_errors = check(app_configs=app_configs, databases=databases)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/edward/anaconda3/envs/arete/lib/python3.11/site-packages/django/core/checks/urls.py", line 42, in check_url_namespaces_unique
    all_namespaces = _load_all_namespaces(resolver)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/edward/anaconda3/envs/arete/lib/python3.11/site-packages/django/core/checks/urls.py", line 61, in _load_all_namespaces
    url_patterns = getattr(resolver, "url_patterns", [])
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/edward/anaconda3/envs/arete/lib/python3.11/site-packages/django/utils/functional.py", line 57, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
                                         ^^^^^^^^^^^^^^^^^^^
  File "/home/edward/anaconda3/envs/arete/lib/python3.11/site-packages/django/urls/resolvers.py", line 715, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
                       ^^^^^^^^^^^^^^^^^^^
  File "/home/edward/anaconda3/envs/arete/lib/python3.11/site-packages/django/utils/functional.py", line 57, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
                                         ^^^^^^^^^^^^^^^^^^^
  File "/home/edward/anaconda3/envs/arete/lib/python3.11/site-packages/django/urls/resolvers.py", line 708, in urlconf_module
    return import_module(self.urlconf_name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/edward/anaconda3/envs/arete/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1149, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/home/edward/Desktop/arete/backend/core/urls.py", line 35, in <module>
    path('api/', include(('question_judge.urls', 'question_judge'),
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/edward/anaconda3/envs/arete/lib/python3.11/site-packages/django/urls/conf.py", line 38, in include
    urlconf_module = import_module(urlconf_module)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/edward/anaconda3/envs/arete/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1149, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/home/edward/Desktop/arete/backend/question_judge/urls.py", line 3, in <module>
    from question_judge.views import (QuestionViewSet, QuestionSubmissionViewSet, SolutionViewSet,
  File "/home/edward/Desktop/arete/backend/question_judge/views.py", line 21, in <module>
    from question_judge.serializers import (
  File "/home/edward/Desktop/arete/backend/question_judge/serializers.py", line 8, in <module>
    from question_judge.utils import verify_answer
  File "/home/edward/Desktop/arete/backend/question_judge/utils.py", line 11, in <module>
    test = require('@cortex-js/compute-engine')
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/edward/anaconda3/envs/arete/lib/python3.11/site-packages/javascript/__init__.py", line 37, in require
    return config.global_jsi.require(name, version, calling_dir, timeout=900)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/edward/anaconda3/envs/arete/lib/python3.11/site-packages/javascript/proxy.py", line 218, in __call__
    else self._exe.callProp(
         ^^^^^^^^^^^^^^^^^^^
  File "/home/edward/anaconda3/envs/arete/lib/python3.11/site-packages/javascript/proxy.py", line 158, in callProp
    resp = self.pcall(ffid, "call", method, args, timeout=timeout, forceRefs=forceRefs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/edward/anaconda3/envs/arete/lib/python3.11/site-packages/javascript/proxy.py", line 146, in pcall
    raise JavaScriptError(attr, res["error"])
javascript.errors.JavaScriptError: ('require', "Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@cortex-js/compute-engine' imported from /home/edward/anaconda3/envs/arete/lib/python3.11/site-packages/javascript/js/deps.js\n    at new NodeError (node:internal/errors:399:5)\n    at packageResolve (node:internal/modules/esm/resolve:783:9)\n    at moduleResolve (node:internal/modules/esm/resolve:832:20)\n    at defaultResolve (node:internal/modules/esm/resolve:1069:11)\n    at DefaultModuleLoader.resolve (node:internal/modules/esm/loader:305:12)\n    at DefaultModuleLoader.getModuleJob (node:internal/modules/esm/loader:156:32)\n    at DefaultModuleLoader.import (node:internal/modules/esm/loader:265:12)\n    at importModuleDynamically (node:internal/modules/cjs/loader:1185:37)\n    at importModuleDynamicallyWrapper (node:internal/vm/module:428:21)\n    at importModuleDynamically (node:internal/vm:105:46)")

@extremeheat
Copy link
Owner

What is the Python code that triggered this error?

@edward1127
Copy link
Author

edward1127 commented Dec 15, 2023

Here's the code

from javascript import require
test = require('@cortex-js/compute-engine')

@extremeheat
Copy link
Owner

Can you link to a notebook that reproduces the error?

@edward1127
Copy link
Author

edward1127 commented Dec 15, 2023

pip install -r requirements.txt
python manage.py runserver

running directly in sandbox will fail, so you might need to reproduce it by cloning the code into your local and run the commands above.

sandbox

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants