Skip to content

Fix CLI yargs import on Node 22+ and add option integration test - #50

Merged
maxnachlinger merged 1 commit into
walmartlabs:masterfrom
mangeshraut712:fix/yargs-import-node26
Nov 11, 2026
Merged

maxnachlinger merged 1 commit into
walmartlabs:masterfrom
mangeshraut712:fix/yargs-import-node26

Conversation

@mangeshraut712

Copy link
Copy Markdown
Contributor

Fixes #49.

Problem

In app.js, const yargs = require("yargs/yargs"); references ./yargs without a file extension from yargs package exports. In Node 22+, requiring extensionless subpath exports triggers the ESM loader, which crashes with:

ReferenceError: require is not defined in ES module scope, you can use import instead
    at .../node_modules/yargs/yargs:3:69

This causes cat test/fixtures/complex.json | node app.js to crash, and test/integration.spec.js fails with empty stdout.

Solution

  • Change require("yargs/yargs") to require("yargs") in app.js, which resolves to index.cjs via the package root export.
  • Add an integration test in test/integration.spec.js asserting that CLI options (--baseType, --prefix) are accepted and produce the expected schema.

Local verification

$ ./node_modules/.bin/prettier --check app.js test/integration.spec.js
Checking formatting...
app.js
test/integration.spec.js
All matched files use Prettier code style!

$ ./node_modules/.bin/eslint app.js test/integration.spec.js
# (clean exit 0)

$ ./node_modules/.bin/jest
PASS test/integration.spec.js
PASS test/complex-json.spec.js
PASS test/stringify-schema.spec.js
PASS test/simple-json.spec.js
PASS test/validate-json.spec.js
PASS test/remove-duplicate-types.spec.js
PASS test/bad-character-input.spec.js
PASS test/array-of-array-property.spec.js

Test Suites: 8 passed, 8 total
Tests:       12 passed, 12 total
Snapshots:   0 total
Time:        0.54 s, estimated 1 s
Ran all test suites.

@mangeshraut712

Copy link
Copy Markdown
Contributor Author

Hi, a gentle check-in on this one. It is a one-line fix for the Node 22+ crash in #49, and the integration test passes with it. Is there anything else you would like changed before it can be merged?

@maxnachlinger

Copy link
Copy Markdown
Contributor

Forgive the late reply, this repo is not been used in years and has not been well maintained. We've found Rust to be a good fit for the scale at which we operate via a vis GraphQL. 🙂 Thanks for the contribution!

@maxnachlinger
maxnachlinger merged commit 47b855c into walmartlabs:master Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

CLI crashes on Node 26, integration test fails (yargs ESM require error)

2 participants