cli: ERR_REQUIRE_ESM const wrap = require("wrap-ansi");
Issue summary
Often (but not always) when I run yarn dev
to start the project I get this error below. This happens to my colleague too on a different computer, on a different project, both are new projects from the shopify remix template.
My colleague reports that if he switches from yarn to npm then the problem goes away. If I rm -rf
node_modules
and yarn.lock
, then run yarn
again it usually goes away.
➜ shopify-reports git:(main) yarn dev
yarn run v1.22.19
$ prisma generate && prisma migrate deploy
Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
✔ Generated Prisma Client (4.16.2 | library) to ./node_modules/@prisma/client in 46ms
You can now start using Prisma Client in your code. Reference: https://pris.ly/d/client
import { PrismaClient } from ‘@prisma/client’ const prisma = new PrismaClient()
Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
Datasource "db": SQLite database "dev.sqlite" at "file:dev.sqlite"
1 migration found in prisma/migrations
No pending migrations to apply.
$ shopify app dev
/Users/alex/dev/micro/shopify-reports/node_modules/@oclif/core/lib/errors/errors/pretty-print.js:4
const wrap = require("wrap-ansi");
^
Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/alex/dev/micro/shopify-reports/node_modules/wrap-ansi/index.js from /Users/alex/dev/micro/shopify-reports/node_modules/@oclif/core/lib/errors/errors/pretty-print.js not supported.
Instead change the require of index.js in /Users/alex/dev/micro/shopify-reports/node_modules/@oclif/core/lib/errors/errors/pretty-print.js to a dynamic import() which is available in all CommonJS modules.
at Object.<anonymous> (/Users/alex/dev/micro/shopify-reports/node_modules/@oclif/core/lib/errors/errors/pretty-print.js:4:14)
at Object.<anonymous> (/Users/alex/dev/micro/shopify-reports/node_modules/@oclif/core/lib/errors/handle.js:7:24)
at Object.<anonymous> (/Users/alex/dev/micro/shopify-reports/node_modules/@oclif/core/lib/errors/index.js:4:16)
at Object.<anonymous> (/Users/alex/dev/micro/shopify-reports/node_modules/@oclif/core/lib/cli-ux/index.js:4:16)
at Object.<anonymous> (/Users/alex/dev/micro/shopify-reports/node_modules/@oclif/core/lib/command.js:7:18)
at Object.<anonymous> (/Users/alex/dev/micro/shopify-reports/node_modules/@oclif/core/lib/index.js:5:19) {
code: 'ERR_REQUIRE_ESM'
}
Node.js v18.18.2
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
About this issue
- Original URL
- State: closed
- Created 7 months ago
- Reactions: 9
- Comments: 19 (9 by maintainers)
I get a similar issue using Node 20.10.0.
I have the same issue:
yarn add any-package -W
andyarn run dev
is enough to trigger it. Removingyarn.lock
andnode_modules
fixes but it’s quite annoyingJust add this to your
package.json
and should be good:(and remember to remove yarn.lock and node_modules and do a clean install after)