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 failing with ReferenceError: require is not defined in ES module scope #504

Closed
tmtmtmtm opened this issue Dec 8, 2022 · 1 comment
Closed

Comments

@tmtmtmtm
Copy link

tmtmtmtm commented Dec 8, 2022

Today I updated to the latest release from a significantly older version, and now running the cli script is failing:

> wtf_wikipedia https://en.wikipedia.org/wiki/Kaja_Kallas
file:///usr/local/lib/node_modules/wtf_wikipedia/cli.js:2
const wtf = require('./src/index')
            ^

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 '/usr/local/lib/node_modules/wtf_wikipedia/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
    at file:///usr/local/lib/node_modules/wtf_wikipedia/cli.js:2:13
    at ModuleJob.run (node:internal/modules/esm/module_job:194:25)

Node.js v19.2.0

It's possible that something has gone awry in my local environment, but from some brief googling, it looks like Node 14 changed the behaviour of require if package.json declares type: module. So I think that either that should be changed totype: commonjs, or the import mechanism in cli.js should be changed, but I'm a little out of my depth here.

spencermountain added a commit that referenced this issue Dec 8, 2022
@spencermountain spencermountain mentioned this issue Dec 8, 2022
Merged
@spencermountain
Copy link
Owner

good catch!
fixed in 10.0.5.
thanks

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