1
votes

question: how to let Angular look inside the node_modules folder instead of the 'custom directory defined in package.json' when including files from a custom npm-module. (see package.json below)


In my project i have 2 folders

  • root
    • angular
      • src
      • package.json
    • shared (npm module)
      • src
      • package.json

within the directory of angular, i install my custom npm module through the normal npm install. here is the package.json file

 {
  "name": "angular",
  "dependencies": {
    "shared-module": "file:../shared-module"
  }

i can see its installed correctly by checking the node_modules folder of the angular directory

  • root
    • angular
      • node_modules
        • shared-module
          • src

then when I include a file from the shared-module in the angular project

import 'shared-module/src/util/countries';

it doesn't seem to look inside the angular->node_modules folder, but instead keeps going to the 'original' directory of the custom npm module ..

ERROR in ../shared-module/src/util/countries.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.

if I update the tsconfig.json to include the 'original' directory, it works..

"include": [
  "./src/**/*.ts",
  "../shared-modules//src/**/*.ts"
]

But then there is no real point adding it to the package.json with (unless you publish the module)

"shared-module": "file:../shared-module"

So it feels like I am missing some settings maybe? Thanks in advance


edit: it seems NPM 5 creates a symlink when using it like this

"shared-modules": "file:../shared-module"

edit2: preserveSymlinks doesn't seem to do anything (https://www.typescriptlang.org/docs/handbook/compiler-options.html)

anyway around that behavior and just really install the package?

1
What did you use to build the custom module?slasky
Don't know if I understand the question, but I used nothing to build.. Use-case: the angular project includes some .ts files from custom module and uses these files to compile / build an Angular output.. The shared folder does not need to be 'pre-build'DutchKevv
Okay I misunderstood. I thought you were installing a custom-packed npm module into your app.slasky
Ah yes that is correct :) I have to work on my SO skills, i'm sorry (second post or so).. The module is installed correctly, but when I import a file from the module, it doesn't go to the node_modules folder, but instead to the 'original' path of the custom_module, and thus brakes the scope of the folder.. question is: how to let typescript NOT follow the symlink and instead treat is a 'local' module from the angular own node_module folder? Thanks ;)DutchKevv

1 Answers

0
votes

When I work with uncompiled libraries that I might want to edit and have angular pick up changes right away, I add them to "paths" of tsconfig or use "npm link"