D
D
Dmitry Kuznetsov2022-02-01 09:09:14
typescript
Dmitry Kuznetsov, 2022-02-01 09:09:14

Why are modules not being imported from node_modules in TS?

Good afternoon. A Node.js application is being written on TS without any assemblers. When building the project, all imports from node_modules are not connected and an error is generated, respectively. How can I make the import of libraries work correctly (without using bundlers a la Webpack, etc.)?

tsconfig.json:

{
  "compileOnSave": true,
  "compilerOptions": {
    "target": "ESNext",
    "module": "CommonJS",
    "esModuleInterop": true,
    "moduleResolution": "Node",
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "noImplicitAny": true,
    "removeComments": true,
    "preserveConstEnums": true,
    "sourceMap": false,
    "outDir": "../../packages/project",
    "rootDir": "src"
  },
  "include": [
    "src/**/*"
  ],
  "exclude": ["node_modules"],   // Комментирование этой строчки ни чего не даёт
  "watchOptions": {
    "watchFile": "useFsEvents",
    "watchDirectory": "useFsEvents",
    "fallbackPolling": "dynamicPriority",
    "synchronousWatchDirectory": true,
    "excludeDirectories": ["**/node_modules", "_build"],  // Комментирование этой строчки ни чего не даёт
    "excludeFiles": ["build/fileWhichChangesOften.ts"]
  }
}


package.json:
{
  "name": "server",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "dev": "tsc",
    "watch": "tsc --watch"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@types/node": "^17.0.12",
    "@types/validator": "^13.7.1",
    "typescript": "^4.5.5"
  },
  "dependencies": {
    "dotenv": "^14.3.2",
    "pg": "^8.7.1",
    "pg-hstore": "^2.3.4",
    "reflect-metadata": "^0.1.13",
    "sequelize": "^6.14.1"
  }
}


The import is pretty simple:
import { Sequelize, Dialect } from 'sequelize';

// код подключения к БД


And the error is this:
Error: Cannot find module 'sequelize'

PS: If the library is definitely installed in the project. Referring to the problem of the TS collector. I didn’t work much with TS and maybe I configured something incorrectly.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question