Skip to content

pidtree upsets the ESM parser in node 22 #28

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

Open
gavinaiken opened this issue Feb 28, 2025 · 0 comments · May be fixed by #29
Open

pidtree upsets the ESM parser in node 22 #28

gavinaiken opened this issue Feb 28, 2025 · 0 comments · May be fixed by #29

Comments

@gavinaiken
Copy link

We are using pidtree in a large node project with many modules. Our project is all ESM but it depends on a number of npm modules which are a mix of ESM and commonjs. When we upgraded to node 22 recently we found that pidtree as it is seems to upset the node static analysis of other commonjs modules, causing them not to load, eg with errors like this:

import { Emitter } from "@socket.io/component-emitter";
         ^^^^^^^
SyntaxError: Named export 'Emitter' not found. The requested module '@socket.io/component-emitter' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from '@socket.io/component-emitter';
const { Emitter } = pkg;

    at ModuleJob._instantiate (node:internal/modules/esm/module_job:180:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:263:5)
    at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:578:26)

Removing our use of pidtree made the errors go away. I believe this is a node bug, but unfortunately I have not yet been successful in creating a minimal reproduction of the issue - everything just works as expected with a small/simple project of only a few modules. Without a simple repro I don't see a lot of point in opening an issue on the core node project.

Anyway, we wanted to continue using pidtree as it is useful so I refactored it to ESM which made the problem go away. I will create a PR in case you wish to consider this for merger, and also thought this issue might be useful to others if they encounter the same issue.

@gavinaiken gavinaiken linked a pull request Feb 28, 2025 that will close this issue
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.

1 participant