nrwl / nx-orb

✨ A CircleCI Orb which includes helpful commands for running Nx commands in the CI
https://github.com/nrwl/nx-orb
MIT License
20 stars 23 forks source link

Bug: Does not work in esm projects #56

Open kasperpeulen opened 4 months ago

kasperpeulen commented 4 months ago

Orb version:

1.6.2

What happened:

Got an error, that it can not run a common js script in a type: module package:

file:///tmp/storybook/index.js:2
const { execSync } = require('child_process');
                     ^

ReferenceError: require is not defined in ES module scope, you can use import instead
This file is being treated as an ES module because it has a '.js' file extension and '/tmp/storybook/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
    at file:///tmp/storybook/index.js:2:22
    at ModuleJob.run (node:internal/modules/esm/module_job:195:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:336:24)
    at async loadESM (node:internal/process/esm_loader:34:7)
    at async handleMainPromise (node:internal/modules/run_main:106:12)

Node.js v18.19.1

Expected behavior:

Should work also in an ESM environment. Changing the name to index.cjs would fix this. Allthough it is kind of weird that this script is added to the package.

Additional Information:

mandarini commented 1 month ago

Hi there @kasperpeulen ! Thank you for the enhancement request, and thank you for your patience too. Do you have a suggested implementation for this? Would you like to submit a PR?

kasperpeulen commented 1 month ago

I think that changing the name to index.cjs would fix this.