hmenyus / node-calls-python

Call Python from NodeJS directly in-process without spawning processes
MIT License
252 stars 26 forks source link

Error: The requested module 'node-calls-python' does not provide an export named 'default #81

Closed josephjclark closed 6 months ago

josephjclark commented 6 months ago

Since updating to 1.9.0 (from 1.8.4) I'm seeing this in npm (and bun, for what it's worth).

image

The new index.mjs seems to be messing the import up. I have "type": "module" set in my package.json.

If I add export default cjs to index.mjs it all seems to work (although I haven't done a test with a cjs project)

hmenyus commented 6 months ago

Added export defaults in 1.9.1

josephjclark commented 6 months ago

Thank you. This works - although I have had to change my ESM import.

I was doing this in 1.8.4, which is still broken in 1.9.1:

import ncp from "node-calls-python";
const py = ncp.interpreter

This seems to me to be a direct equivalent of:

const ncp = require("node-calls-python");
const py = ncp.interpreter;

But I've just checked your docs on ESM, and your documented approach works fine. So I've changed my imports and I consider this closed.

As a point of wider feedback, this is the state of imports right now - all these are the same so far as I can tell:

// basic CJS import, per docs
const nodecallspython = require('node-calls-python')
const py = nodecallspython.interpreter;

// cjs with deconstruction should work, although I haven't tested it
const { interpreter as py } = require('node-calls-python')

// ESM works as documented
import { interpreter as py } from 'node-calls-python';

// default ESM is a bit different (and way nicer btw)
import py from 'node-calls-python';

This is a breaking change, but my feedback would be to make interpreter the only and default export from CJS and ESM, so that I can just do:

const py = require('node-calls-python') // CJS
import py from 'node-calls-python'; // ESM

py.import('script.py')

And all your documented code examples get a little bit simpler