Skip to content

Can't use d3 lib with NestJS #10239

@dminglv

Description

@dminglv

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

Hello! I have problems with using the d3 package.

Require package use ES Module, but NestJS don't support this and I cant't use this module.

Minimum reproduction code

https://github.com/dminglv/nestjs-d3

Steps to reproduce

No response

Expected behavior

The third-party library is not imported (d3)

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

d3

NestJS version

9.0.11

Packages versions

"dependencies": {
    "@nestjs/common": "^9.0.11",
    "@nestjs/core": "^9.0.11",
    "@nestjs/platform-express": "^9.0.11",
    "d3": "^7.6.1",
    "reflect-metadata": "^0.1.13",
    "rimraf": "^3.0.2",
    "rxjs": "^7.5.6"
  },
  "devDependencies": {
    "@nestjs/cli": "^9.1.2",
    "@nestjs/schematics": "^9.0.3",
    "@nestjs/testing": "^9.0.11",
    "@types/d3": "^7.4.0",
    "@types/express": "^4.17.13",
    "@types/jest": "29.0.0",
    "@types/node": "^18.7.15",
    "@types/supertest": "^2.0.12",
    "@typescript-eslint/eslint-plugin": "^5.36.1",
    "@typescript-eslint/parser": "^5.36.1",
    "eslint": "8.22.0",
    "eslint-config-prettier": "^8.5.0",
    "eslint-plugin-prettier": "^4.2.1",
    "jest": "29.0.2",
    "prettier": "^2.7.1",
    "source-map-support": "^0.5.21",
    "supertest": "^6.2.4",
    "ts-jest": "28.0.8",
    "ts-loader": "^9.3.1",
    "ts-node": "^10.9.1",
    "tsconfig-paths": "4.1.0",
    "typescript": "^4.8.2"
  },

Node.js version

18.8.0

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

/Users/dmitrii/WebstormProjects/nestjs-d3/dist/app.service.js:11
const d3 = require("d3");

Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/dmitrii/WebstormProjects/nestjs-d3/node_modules/d3/src/index.js from /Users/dmitrii/WebstormProjects/nestjs-d3/dist/app.service.js not supported.
Instead change the require of index.js in /Users/dmitrii/WebstormProjects/nestjs-d3/dist/app.service.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/Users/dmitrii/WebstormProjects/nestjs-d3/dist/app.service.js:11:12)
    at Object.<anonymous> (/Users/dmitrii/WebstormProjects/nestjs-d3/dist/app.controller.js:14:23)
    at Object.<anonymous> (/Users/dmitrii/WebstormProjects/nestjs-d3/dist/app.module.js:11:26)
    at Object.<anonymous> (/Users/dmitrii/WebstormProjects/nestjs-d3/dist/main.js:4:22)

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs triageThis issue has not been looked into

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions