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

Bug: Does not work in esm projects #56

Open
kasperpeulen opened this issue Mar 27, 2024 · 2 comments
Open

Bug: Does not work in esm projects #56

kasperpeulen opened this issue Mar 27, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@kasperpeulen
Copy link

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
Copy link
Member

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants