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

CLI error on node.js in latest version but not previous #32

Closed
cmdcolin opened this issue Jan 29, 2025 · 3 comments
Closed

CLI error on node.js in latest version but not previous #32

cmdcolin opened this issue Jan 29, 2025 · 3 comments

Comments

@cmdcolin
Copy link

straw ~/Downloads/intra_nofrag_30.hic --norms
file:///home/cdiesh/.fnm/node-versions/v22.11.0/installation/lib/node_modules/hic-straw/cli.js:3
const Straw = require("./dist/hic-straw.js");
              ^

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 '/home/cdiesh/.fnm/node-versions/v22.11.0/installation/lib/node_modules/hic-straw/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
    at file:///home/cdiesh/.fnm/node-versions/v22.11.0/installation/lib/node_modules/hic-straw/cli.js:3:15
    at ModuleJob.run (node:internal/modules/esm/module_job:268:25)
    at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:543:26)
    at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:116:5)

Node.js v22.11.0

might be related to the type:module addition, tricky stuff

I found getting an older version does work though

$ npm install -g "hic-straw@v2.0.3" 
$ npm install -g "node-fetch@^2.0.0"       
$ straw intra_nofrag_30.hic --norms 
@cmdcolin
Copy link
Author

(note that i install node-fetch v2 there also because it is the last version that was cjs compatible, i believe v3 is esm)

@jrobinso
Copy link
Contributor

Hmm, hic-straw.js is an esm module, I would not expect require to work, but OTOH we use it (require) in our examples.

I don't know how this worked earlier, but I think you are correct the "type: module" change is the culprit here.

Perhaps we should build a common js module as well (hic-straw.cjs) as well as the esm module.

Ping this again if its not fixed in a few days, I'm busy with another issue at the moment.

@cmdcolin
Copy link
Author

yes, it is no rush, i just stumbled on this helping a biostars issue :)

https://www.biostars.org/p/9608388/

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

No branches or pull requests

2 participants