Open spike-rabbit opened 1 week ago
Can you please elaborate more on how you got this error (and your proposed fix?)
Thx for replying and taking care.
Sorry for the initial incomplete description. I now added a reproduction repo and slightly improved solution suggestions. I can create a PR once you decided for a preferred solution approach.
Can't reproduce on a new github codespace:
➜ /workspaces/python-js-module-bug (main) $ poetry install
Creating virtualenv python-js-module-WaJCDlOP-py3.12 in /home/codespace/.cache/pypoetry/virtualenvs
Installing dependencies from lock file
Package operations: 1 install, 0 updates, 0 removals
- Installing javascript (1!1.2.1)
➜ /workspaces/python-js-module-bug (main) $ poetry run python python-that-imports-js.py
[
'.git',
'.gitignore',
'README.md',
'module-based-js-file.js',
'package-lock.json',
'package.json',
'poetry.lock',
'pyproject.toml',
'python-that-imports-js.py'
]
➜ /workspaces/python-js-module-bug (main) $ node --version
v20.17.0
➜ /workspaces/python-js-module-bug (main) $ python --version
Python 3.12.1
This works as your .venv
is not in /workspaces/python-js-module-bug
.
So the projects package.json is not interfering with the .venv js files.
Reproduction Repo: https://github.com/spike-rabbit/python-js-module-bug The important part is, that the venv are in the same directory or below the projects
package.json
.Error:
Potential solutions
Sure, I could move things around in my project to get rid of the module problem.
But the much nicer solutions would be either:
.js
files provided by thejavascript
module all have.cjs
ending to ensure they are always treated as commonjspackage.json
inside thejavascript
module that explicitly declare{"type": "commonjs"}