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

ERR_REQUIRE_ESM #39

Closed
whalemare opened this issue Jun 30, 2021 · 2 comments
Closed

ERR_REQUIRE_ESM #39

whalemare opened this issue Jun 30, 2021 · 2 comments

Comments

@whalemare
Copy link

When I run with ts-node I have next error

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /node_modules/terminal-image/index.js
require() of ES modules is not supported.
require() of /node_modules/terminal-image/index.js from /src/cli/commands/new/newCommand.ts is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /node_modules/terminal-image/package.json.

    at new NodeError (node:internal/errors:363:5)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1112:13)
    at Module.load (node:internal/modules/cjs/loader:975:32)
    at Function.Module._load (node:internal/modules/cjs/loader:816:12)
    at Module.require (node:internal/modules/cjs/loader:999:19)
    at require (node:internal/modules/cjs/helpers:93:18)
    at Object.<anonymous> (/src/cli/commands/new/newCommand.ts:10:1)
    at Module._compile (node:internal/modules/cjs/loader:1095:14)
    at Module.m._compile (/ts-node/src/index.ts:1295:23)
    at Module._extensions..js (node:internal/modules/cjs/loader:1124:10)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
@sindresorhus
Copy link
Owner

https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c

@danilvalov
Copy link

If you have this issue use the following import solution instead of simple import terminalImage from 'terminal-image'; from examples:

const { default: terminalImage } = await import('terminal-image');

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

3 participants