Error [ERR_REQUIRE_ESM]: require() of ES Module /home/sky/Documents/hourlypets/node_modules/tsl-mastodon-api/lib/index.js from /home/sky/Documents/hourlypets/src/mastodon.ts not supported.
Instead change the require of index.js in /home/sky/Documents/hourlypets/src/mastodon.ts to a dynamic import() which is available in all CommonJS modules.
at require.extensions. [as .js] (/usr/lib/node_modules/ts-node/dist/index.js:851:20)
at Object. (/home/sky/Documents/hourlypets/src/mastodon.ts:36:31)
at m._compile (/usr/lib/node_modules/ts-node/dist/index.js:857:29)
at require.extensions. [as .ts] (/usr/lib/node_modules/ts-node/dist/index.js:859:16)
at Object. (/home/sky/Documents/hourlypets/src/bot.ts:13:20)
at m._compile (/usr/lib/node_modules/ts-node/dist/index.js:857:29)
at require.extensions. [as .ts] (/usr/lib/node_modules/ts-node/dist/index.js:859:16)
at phase4 (/usr/lib/node_modules/ts-node/dist/bin.js:466:20)
at bootstrap (/usr/lib/node_modules/ts-node/dist/bin.js:54:12)
at main (/usr/lib/node_modules/ts-node/dist/bin.js:33:12)
at Object. (/usr/lib/node_modules/ts-node/dist/bin.js:579:5) {
code: 'ERR_REQUIRE_ESM'
}
I am importing the lib like this
import * as Mastodon from 'tsl-mastodon-api';
My first impression is that it says you're trying to load an ES Module using a CommonJS
require()
call. Evidently from your code snippet, that's not the case. My guess would be that Typescript is transpiling your code to CommonJS modules, and that the library you're trying to import only exports ES modules (or at-least that's what NodeJS is trying to import for one reason or another).You may have to modify something in your
tsconfig.json
file to tell it to transpile to ESM instead of CommonJS.