Why would some Angular modules import while other do not?

I have a problem with a module that I cant seem to get to import.

Typescript 2.7 Node 10

pxl-ng-security shows an error in VSCode and VS2019. If I hover over it, it shows error 2307

Here is the import section of the file.

myfile.ts

import { Injectable } from '@angular/core';
import { Headers, Http, Response } from '@angular/http';
import { TokenService } from 'pxl-ng-security';

The gulp file is pointing to tsconfig-library.json so I believe the means its using that file instead of the standard tsconfig.json.

tsconfig-library.json

{
  "compilerOptions": {
    "target": "es5",
    "lib": ["es2015", "dom"],
    "module": "es2015",
    "moduleResolution": "node",
    "declaration": true,
    "experimentalDecorators": true,
    "baseUrl": ".",
    "stripInternal": true,
    "outDir": "./dist",
    "rootDir": "./src-embedded",
    "sourceMap": true,
    "inlineSources": true,
    "skipLibCheck": true
  },
  "files": [
    "./src-embedded/index.ts"
  ],
  "angularCompilerOptions": {
    "skipTemplateCodeGen": true
  }
}

tsconfig.json

{
  "compileOnSave": false,
  "compilerOptions": {
    "outDir": "./out-tsc",
    "baseUrl": "src",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2016",
      "dom"
    ]
  }
}

I have tried using ../../node_modules/pxl-ng-security and it has the same problem. Intellisense sees it and fill it in. I have confirmed that the folder is indeed in that location. I have deleted it from node_modules and done a npm-install -project-local and the module comes back, so it would seem the module is healthy and correct.

Running tsc -p . gives the following error

error TS2307: Cannot find module 'pxl-ng-security' or its corresponding type declarations.

If I go ahead and try and run gulp the error is"

Error: Error encountered resolving symbol values statically. Could not resolve pxl-ng-security

New Details. I jumped on a CI/CD server and noticed that this is building fine. Same code working on it. I installed vscode on it, just to see if it showed the same ts2307 error. It was fine. I checked versions of Node and Typescript and they both match. The mystery continues

1 answer

  • answered 2021-05-15 01:09 Transformer

    You are missing the include: array just add/update the include array per where you installed it.

    {
      "compileOnSave": false,
      "compilerOptions": {
        "outDir": "./out-tsc",
        "baseUrl": "src",
        "sourceMap": true,
        "declaration": false,
        "moduleResolution": "node",
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "target": "es5",
        "typeRoots": [
          "node_modules/@types"
        ],
        "lib": [
          "es2016",
          "dom"
        ]
      },
      // you are missing the includes array
      "include": [
         "src/**/*.ts", 
         "tests/**/*.ts",
         // ADD your module here below**** with correct path
         "node_modules/pxl-ng-security"
       ],
      //"exclude": ["node_modules", ".vscode"]
    }