Home > other >  TS: Cannot find module 'follow-redirects'
TS: Cannot find module 'follow-redirects'

Time:03-14

I am trying to use this library based on this answer:

Once I run npm install @types/follow-redirects , VS suggests follow-redirects without problems, so I end up having this in my code:

import { https } from "follow-redirects"

The problem comes when I try to compile this (when doing firebase deploy). I get an error saying: Error: Cannot find module 'follow-redirects'.

As you can see in my package.json, I am using other dependencies without problem:

{
  "name": "functions",
  "scripts": {
    "lint": "eslint --ext .js,.ts .",
    "build": "tsc",
    "serve": "npm run build && firebase emulators:start --only functions",
    "shell": "npm run build && firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "engines": {
    "node": "16"
  },
  "main": "lib/index.js",
  "dependencies": {
    "@types/follow-redirects": "^1.14.1",
    "express": "^4.17.1",
    "firebase": "^9.6.3",
    "firebase-admin": "^9.8.0",
    "firebase-functions": "^3.18.1",
    "http-status-codes": "^1.3.2"
  },
  "devDependencies": {
    "@types/chai": "^4.2.11",
    "@types/mocha": "^7.0.2",
    "@typescript-eslint/eslint-plugin": "^3.9.1",
    "@typescript-eslint/parser": "^3.8.0",
    "chai": "^4.2.0",
    "eslint": "^7.6.0",
    "eslint-config-google": "^0.14.0",
    "eslint-plugin-import": "^2.22.0",
    "firebase-functions-test": "^0.2.0",
    "mocha": "^7.1.1",
    "typescript": "^3.8.0"
  },
  "private": true
}

So not sure if the problem is coming from firebase, this library or maybe I made a mistake somewhere.

CodePudding user response:

You installed and saved the @types/follow-redirects package (which includes type definitions that allow better code completion) but haven't saved the follow-redirects package itself. Try running npm install --save follow-redirects (so the package is saved in package.json) and then deploying.

  • Related