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

Throws error in monorepo that has a package.json at the toplevel #861

Closed
vikigenius opened this issue Nov 8, 2024 · 3 comments · Fixed by #862
Closed

Throws error in monorepo that has a package.json at the toplevel #861

vikigenius opened this issue Nov 8, 2024 · 3 comments · Fixed by #862

Comments

@vikigenius
Copy link

I have a monorepo that has both a pyproject.toml and a package.json at the toplevel

I install basedpyright in my virtual environment:

Using

uv add --dev basedpyright

It seems like basedpyright is somehow using my package.json when it shouldn't

file:///home/void/Projects/Python/chatpyre/.venv/lib/python3.12/site-packages/basedpyright/index.js:6
global.__rootDirectory = __dirname + '/dist/';
                         ^

ReferenceError: __dirname is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and '/home/void/Projects/Python/chatpyre/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
    at file:///home/void/Projects/Python/chatpyre/.venv/lib/python3.12/site-packages/basedpyright/index.js:6:26
    at ModuleJob.run (node:internal/modules/esm/module_job:268:25)
    at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:543:26)
    at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:116:5)

Node.js v22.11.0
@DetachHead DetachHead added the needs investigation awaiting verification by a maintainer that the issue is valid label Nov 9, 2024
@DetachHead
Copy link
Owner

oh wow, i also have a project with both a top-level pyproject.toml and package.json but never ran into this issue because it doesn't use "type": "module"

@DetachHead DetachHead removed the needs investigation awaiting verification by a maintainer that the issue is valid label Nov 9, 2024
@vikigenius
Copy link
Author

Yep. I tried a bunch of things and don't know if there is a way to have something that works for both cjs and module.

There also doesn't seem to be a way to ignore the package.json

The easiest solution is probably to also bundle a minimal package.json alongside the index.js file to make sure it only uses that one.

@vikigenius
Copy link
Author

vikigenius commented Nov 9, 2024

Adding an empty package.json alongside index.js fixes this issue

By empty, I mean just the {}.

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

Successfully merging a pull request may close this issue.

2 participants