http is not recognized in the Node Express project

Asked

Viewed 74 times

0

My project is giving this error message;

inserir a descrição da imagem aqui

Why is my project not recognizing my http?

I’m new, and I’m still learning to code in Express.

This is my package.json;

{
  "name": "registre",
  "version": "1.0.0",
  "description": "API",
  "main": "server/server.ts",
  "scripts": {
    "start": "./node_modules/.bin/ts-node/ ./server/server.ts",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "Wladimir",
  "license": "ISC",
  "dependencies": {
    "body-parser": "^1.18.3",
    "express": "^4.16.3",
    "http": "0.0.0",
    "morgan": "^1.9.0",
    "pg": "^7.4.3",
    "sequelize-cli": "^4.1.1"
  },
  "devDependencies": {
    "@types/body-parser": "^1.17.0",
    "@types/express": "^4.16.0",
    "@types/morgan": "^1.7.35",
    "@types/sequelize": "^4.27.25",
    "sequelize": "^4.38.0",
    "ts-node": "^7.0.1"
  }
}
  • This problem ai ta related to typescript, because in Babel the same syntax presents no problem. Do not use typescript there do not know what problem kkkk sorry.

  • maybe typescript needs to be installed globally on the operating system, knows which is the command to see which version of typescript is installed on my pc?

  • tsc -v, but I don’t think you need to use the as only the import http from 'http' already resolves.

  • strange, my typescript is installed globally Version 3.0.1

  • So use as I said, without the as, there is no need in this context. And http is the default package.

  • made the same mistake.

Show 2 more comments

2 answers

1

As far as I know you have two options:

  1. (Recommended) Install the @types/Node dependency with npm install @types/node --save-dev.
  2. Create an archive index.d.ts declaring a setting pro modulo http. The file can look like this: declare module 'http

Remembering that this second option will not add auto complete with module methods.

1


As discussed in chat, problem in the version of the standard package of express. Did if necessary the installation of the package compatible with the version of @types.

npm install @type/express current version of @types [email protected]

npm install [email protected]

Problem solved.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.