Missing *.ts files (due to `npm link` ?)

Alexander Mills picture Alexander Mills · Feb 14, 2018 · Viewed 27.2k times · Source

I have this import statement in an Angular5 project:

import {plugins, SCECodeGenType} from 'sce-plugins/code-generation';

this resolves to this path on my filesystem:

/Users/.../suman-chrome-extension/node_modules/sce-plugins/code-generation/index.d.ts

When building the app with ng build -w, I get this error:

ERROR in ../sce-plugins/code-generation/index.ts Module build failed: Error: /Users/alexamil/WebstormProjects/oresoftware/sumanjs/sce-plugins/code-generation/index.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
    at AngularCompilerPlugin.getCompiledFile (/Users/alexamil/WebstormProjects/oresoftware/sumanjs/suman-chrome-extension/node_modules/@ngtools/webpack/src/angular_compiler_plugin.js:662:23)
    at plugin.done.then (/Users/alexamil/WebstormProjects/oresoftware/sumanjs/suman-chrome-extension/node_modules/@ngtools/webpack/src/loader.js:467:39)
    at <anonymous>  @ ./src/app/shared/services/lang.service.ts 14:24-62  @ ./src/app/app.module.ts  @ ./src/main.ts  @ multi ./src/main.ts

I believe it's because I am using npm link to link the 'sce-plugins' project for local development.

I see some issues with using npm link with Angular5 projects here:

https://github.com/angular/angular-cli/issues/3875

https://github.com/angular/angular-cli/issues/8677

https://github.com/angular/angular-cli/issues/9376

anyone know how to fix?

Update:

It does not seem to have do with npm link perse, or symlinks. If I simply copy the local directory over to node_modules/sce-plugins, I get the same damn error. Yet, if I npm install sce-plugins into node_modules then I do not get the error. Very strange, seems like it has to do with angular-cli, not NPM.

Answer

Alexander Mills picture Alexander Mills · Feb 15, 2018

So after reading this Github issue again: https://github.com/angular/angular-cli/issues/8284

I made this change in .angular-cli.json:

  "defaults": {
    "build": {
      "preserveSymlinks": true //   <<<< add this
    },
    "styleExt": "scss",
    "component": {
    }
  }

and now, given that preserveSymlinks flag and the include field in my tsconfig.app.json file:

 "include":[
    "./**/*.ts",
    "../node_modules/sce-plugins/**/*.ts"
  ],

I can now symlink 'sce-plugins' into my main project, instead of manually copying the files. It's possible that you won't need the "include" field at all, although I found that if I removed the "include" field, that it wouldn't work.