spencermountain / wtf_wikipedia

a pretty-committed wikipedia markup parser
https://observablehq.com/@spencermountain/wtf_wikipedia
MIT License
778 stars 129 forks source link

cli failing with ReferenceError: require is not defined in ES module scope #504

Closed tmtmtmtm closed 1 year ago

tmtmtmtm commented 1 year ago

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 commented 1 year ago

good catch! fixed in 10.0.5. thanks