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

@nestjs/cli inquirer dependency requires ESM support #12102

Closed
3 of 15 tasks
fdorantesm opened this issue Jul 23, 2023 · 7 comments
Closed
3 of 15 tasks

@nestjs/cli inquirer dependency requires ESM support #12102

fdorantesm opened this issue Jul 23, 2023 · 7 comments
Labels
needs triage This issue has not been looked into

Comments

@fdorantesm
Copy link

fdorantesm commented Jul 23, 2023

Is there an existing issue for this?

  • I have searched the existing issues

I found an error related with GraphQL module, that's not the same case.

Current behavior

When I try to start my application this error occures, I tried updating @nestjs/cli, node version, setting my package as module but it doesn't work.

Minimum reproduction code

https://github.com/fdorantesm/nestjs-mongodb-hexagonal-template/

Steps to reproduce

  1. Clone repository
  2. Install dependencies $ yarn
  3. Start app $ yarn start:dev

Expected behavior

$ nest start --watch
/Users/nano/workspace/house-keeping-api/node_modules/inquirer/lib/utils/screen-manager.js:4
const wrapAnsi = require('wrap-ansi');
                 ^

Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/nano/workspace/house-keeping-api/node_modules/wrap-ansi/index.js from /Users/nano/workspace/house-keeping-api/node_modules/inquirer/lib/utils/screen-manager.js not supported.
Instead change the require of index.js in /Users/nano/workspace/house-keeping-api/node_modules/inquirer/lib/utils/screen-manager.js to a dynamic import() which is available in all CommonJS modules.

Package

  • I don't know. Or some 3rd-party package
  • @nestjs/common
  • @nestjs/core
  • @nestjs/microservices
  • @nestjs/platform-express
  • @nestjs/platform-fastify
  • @nestjs/platform-socket.io
  • @nestjs/platform-ws
  • @nestjs/testing
  • @nestjs/websockets
  • Other (see below)

Other package

@nestjs/cli

NestJS version

9.4.2

Packages versions

{
  "name": "nestjs-mongodb-hexagonal-template",
  "version": "1.0.0",
  "description": "A nestjs/mongo template using a bit of clean architecture",
  "author": "Fernando Dorantes <fernando@dorant.es>",
  "private": false,
  "license": "MIT",
  "scripts": {
    "prebuild": "rimraf dist",
    "build": "nest build",
    "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\" \"libs/**/*.ts\"",
    "start": "nest start",
    "start:dev": "nest start --watch",
    "start:debug": "nest start --debug --watch",
    "start:prod": "node dist/main",
    "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
    "test": "jest",
    "test:watch": "jest --watch",
    "test:cov": "jest --coverage",
    "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
    "test:e2e": "jest --config ./test/jest-e2e.json --runInBand",
    "hello": "docker-compose up -d",
    "bye": "docker-compose down",
    "compodoc": "compodoc -p tsconfig.json --theme material --output docs",
    "compodoc:serve": "serve -p 6521 docs",
    "docker:publish": "dotenv ./docker.sh"
  },
  "dependencies": {
    "@aws-sdk/client-s3": "^3.345.0",
    "@aws-sdk/client-ses": "^3.348.0",
    "@aws-sdk/s3-request-presigner": "^3.348.0",
    "@nestjs/common": "^9.4.2",
    "@nestjs/config": "^2.3.1",
    "@nestjs/core": "^9.4.2",
    "@nestjs/cqrs": "^9.0.1",
    "@nestjs/devtools-integration": "^0.1.4",
    "@nestjs/jwt": "^10.1.0",
    "@nestjs/mongoose": "^10.0.1",
    "@nestjs/passport": "^10.0.0",
    "@nestjs/platform-express": "^10.1.0",
    "@nestjs/swagger": "^7.1.2",
    "bcrypt": "^5.0.1",
    "class-transformer": "^0.5.1",
    "class-validator": "^0.14.0",
    "connection-string": "^4.3.5",
    "express-rate-limit": "^6.5.2",
    "helmet": "^7.0.0",
    "http-status-codes": "^2.2.0",
    "joi": "^17.6.0",
    "jsonwebtoken": "^8.5.1",
    "lodash": "^4.17.21",
    "luxon": "^3.0.4",
    "mongoose": "^7.4.0",
    "mongoose-paginate": "^5.0.3",
    "nestjs-s3": "^2.0.1",
    "passport": "^0.6.0",
    "passport-jwt": "^4.0.1",
    "pug": "^3.0.2",
    "ramda": "^0.29.0",
    "reflect-metadata": "^0.1.13",
    "rimraf": "^3.0.2",
    "rxjs": "^7.8.0",
    "slugify": "^1.6.6",
    "swagger-ui-express": "^4.6.2",
    "utility": "^1.17.0",
    "uuid": "^9.0.0",
    "volleyball": "^1.5.1"
  },
  "devDependencies": {
    "@compodoc/compodoc": "^1.1.19",
    "@nestjs/cli": "^10.1.10",
    "@nestjs/schematics": "^10.0.1",
    "@nestjs/testing": "^10.1.0",
    "@types/express": "^4.17.17",
    "@types/jest": "27.0.2",
    "@types/luxon": "^3.0.1",
    "@types/mongoose-paginate": "^5.0.12",
    "@types/multer": "^1.4.7",
    "@types/node": "^18.15.0",
    "@types/supertest": "^2.0.11",
    "@typescript-eslint/eslint-plugin": "^5.0.0",
    "@typescript-eslint/parser": "^5.0.0",
    "eslint": "^8.34.0",
    "eslint-config-prettier": "^8.3.0",
    "eslint-plugin-prettier": "^4.0.0",
    "eslint-plugin-yml": "^1.5.0",
    "faker": "5.5.3",
    "husky": "^7.0.4",
    "jest": "^29.3.1",
    "nedb-promises": "^6.2.1",
    "prettier": "^2.3.2",
    "serve": "^14.2.0",
    "source-map-support": "^0.5.20",
    "supertest": "^6.3.3",
    "ts-jest": "^29.0.3",
    "ts-loader": "^9.2.3",
    "ts-node": "^10.0.0",
    "tsconfig-paths": "^3.10.1",
    "typescript": "^5.1.3"
  },
  "jest": {
    "moduleFileExtensions": [
      "js",
      "json",
      "ts"
    ],
    "rootDir": ".",
    "testRegex": ".*\\.spec\\.ts$",
    "transform": {
      "^.+\\.(t|j)s$": "ts-jest"
    },
    "collectCoverageFrom": [
      "**/*.(t|j)s"
    ],
    "coverageDirectory": "./coverage",
    "testEnvironment": "node",
    "roots": [
      "<rootDir>/src/",
      "<rootDir>/libs/",
      "<rootDir>/test/"
    ],
    "moduleNameMapper": {
      "^src/(.*)": "<rootDir>/src/$1",
      "^test/(.*)": "<rootDir>/test/$1",
      "^@app/common(|/.*)$": "<rootDir>/libs/common/src/$1",
      "^@plugins/mongoose-hide-object-id(|/.*)$": "<rootDir>/libs/mongoose-hide-object-id/src/$1",
      "^@app/id-generator(|/.*)$": "<rootDir>/libs/id-generator/src/$1"
    }
  }
}

Node.js version

16.16.0

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

Using MacOS Ventura 13.4.1 (c) (22F770820d)

@fdorantesm fdorantesm added the needs triage This issue has not been looked into label Jul 23, 2023
@micalevisk
Copy link
Member

looks like your package manager's lock file is broken because it has wrap-ansi v8, which is a ESM-only package (see yarn why wrap-ansi).

After rm yarn.lock && yarn install everything went fine here.

@thibault60000
Copy link

Not work for me for a deployment on Heroku
I've tried

"engines": {
    "node": "16.17",
    "yarn": "1.22.19
  }

And

Add engine node & yarn version as local
rm yarn.lock && yarn install
push to git (git deployment method selected)

Not working..

Error on nest build:

/tmp/build_ccf76b34/node_modules/inquirer/lib/utils/screen-manager.js:8
var stripAnsi = require('strip-ansi');
                ^
Error [ERR_REQUIRE_ESM]: require() of ES Module /tmp/build_ccf76b34/node_modules/strip-ansi/index.js from /tmp/build_ccf76b34/node_modules/inquirer/lib/utils/screen-manager.js not supported.
Instead change the require of index.js in /tmp/build_ccf76b34/node_modules/inquirer/lib/utils/screen-manager.js to a dynamic import() which is available in all CommonJS modules.

@fdorantesm
Copy link
Author

That worked for me, try removing the node_modules directory and yarn.lock, then install modules again.

Share a replicable repo if error persists.

@thibault60000
Copy link

Already tried :/
Isn't a local problem. It's a Heroku build problem
I will create a replicate repo

@fdorantesm
Copy link
Author

Already tried :/ Isn't a local problem. It's a Heroku build problem I will create a replicate repo

Try cloning and install dependencies in a clean docker context.

@berenar
Copy link

berenar commented Aug 30, 2023

My two cents here, upgrading to yarn 3 worked for me!

@developer-shkim
Copy link

looks like your package manager's lock file is broken because it has wrap-ansi v8, which is a ESM-only package (see yarn why wrap-ansi).

After rm yarn.lock && yarn install everything went fine here.

@micalevisk
I faced the same problem as the issue, and I solved it by referring to your comment. Thank you!
But I don't know why the esm-only package breaks yarn.lock.

Can you explain it to me?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage This issue has not been looked into
Projects
None yet
Development

No branches or pull requests

5 participants