Angular 5: NPM Link - model/index.ts is not part of the compilation.
Bug Report or Feature Request (mark with an x)
- [x] bug report -> please search issues before submitting
- [ ] feature request
Versions.
Angular CLI: 1.5.0 Node: 8.7.0 OS: darwin x64 Angular: 5.0.0
Repro steps.
We have a the following folder structure in a git mono-repo
/api (Express Node App) /model (NPM package using NPM Link, contains mostly typescript interfaces) /web (Angular)
When using Angular 4.46 and Angular CLI 1.5.rc2 and we were able to make reference to the interfaces defined in the model folder using npm link and using the following example
import { entity } @app/model
We use ng serve to start the app.
After upgrading Angular to V5 and Angular CLI to 1.5.0 we now get the following error -
The log given by the failure.
Module build failed: Error: /Users/thaoula/Projects/platform/model/index.ts is not part of the compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
The occurs for JIT and AOT builds. Running TSC does not result in in errors.
Desired functionality.
Would like be able to build the app using Angular 5
Thanks, Tarek
I don't know if people are still having this problem - here's how I fixed the issue.
I have 2 tsconfig.json files, one at the root of the app, and the other inside the src folder (one level down from the root) named tsconfig.app.json that extends the main tsconfig.json. I explicitly added the package that I needed that wasn't being transpiled by Typescript in the "include" array, and like a lot of people here I was getting the *.spec.ts files included despite having them in "exclude" option, so I removed it from the tsconfig.json. The fix was adding the "exclude" option to the second (extended) tsconfig.app.json file. Doing that fixes the Typescript errors and lets me run ng serve without issue.
Here is tsconfig.json:
{ "compileOnSave": false, "compilerOptions": { "baseUrl": "./src", "outDir": "./dist", "sourceMap": true, "declaration": false, "moduleResolution": "node", "emitDecoratorMetadata": true, "experimentalDecorators": true, "target": "es5", "typeRoots": [ "node_modules/@types" ], "lib": [ "es2017", "dom" ], }, "include": [ "./src", "node_modules/your_package" ] }
And tsconfig.app.json:
{ "extends": "../tsconfig.json", "compilerOptions": { "outDir": "../dist", "baseUrl": "./", "module": "es2015", "types": [] }, "exclude": [ "../node_modules/your_package/**/*.spec.ts" ] }
For some reason adding the exclude in the extended tsconfig (tsconfig.app.json) file is the only way I was able to get it to not complain about the spec files.
Based on the comments from @filipesilva this may still be a bug but it worked for me. Hopefully this helps anyone facing the same issue.
@tapaz1 By following your instruction, I got it work. I added a section of include in tsconfig.json to include the failed module as below:
"include": ["./src", "node_modules/@jaspero/ng2-select"]
then build success. Thank you!
The error also happens when you have the url of a main file wrong in the package.json in your library
we used to compile all files, essentially ignoring what tsconfig listed. This was a bug
IMHO, the new behavior of failing when the compiler wasn't asked to compile a file it wasn't supposed to compile in the first place is also a bug.
we don't really support using incorrectly packaged libraries
npm link is supported by, well, NPM, so it seems odd that angular doesn't. In particular, I've got this in in my .npmignore:
*.ts
!*.d.ts
So that TypeScript files are not included when I npm publish. Perhaps angular could also respect .npmignore files ,and only complain when a .ts file that would be included in a published package is encountered. This would resolve the problems that devs who co-develop an angular site and a related npm package have with this new behavior.
I realize that my situation may be more complicated than most. I've got an angular app and 3 independent NPM packages that I'm working on, where my app depends on all 3 packages, and one of the packages depends on the other two. Two days of googling, RTFMing, and trying every combination of exclude:["foo","bar","bat"] haven't worked for me. (thought oddly "including" them does work, though it brings up another host of other errors b/c I use different versions fo pacakges in my dependences, so there are collisions with the typings between my app's dependencies and my dependencies dependencies.)
In the end, I npm pack'ed my dependencies, installed them in my app from the built .tgz files, put build scripts in my package.json for all my dependencies like so:
npm pack && pushd /my/app/ && npm i /my/dependency/dependency.tgz && popd
all because of this paternalisticl error, that obstructs the use of npm link -- which is a mode of development tool explicitly supported by NPM!
In future, can this be warning instead of an error, or perhaps add a cli flag indicating that no error should be raised just because angular wasn't asked to compile every .ts file it can find?
Workaround:
This error is thrown when loading .js files and .map files, and not when deciding which .ts files to compile. Hence, if:
- you are using
npm linkornpm i file:/my/other/packageto co-develop an angular app and a node package and - you have
"sourceMap": true,in the compiler options of your linked package, and - you have called
tscin your linked repo,
then you can go to the line that threw the error, which is listed in the output from ng serve and comment out the line throw new Error(msg);, and you're off to the races.
The downside to this workaround is that while your ng-serveer will reload your app every time you make changes in your dependency projects -- but it won't compile them and you'll have to restart ng-serve after calling tsc in your dependency in order for updates in your dependencies to be picked up.
In short, the workaround sucks, but at least it doesn't prevent you from doing development on separate projects with separate dependencies and typings.
add in tsconfig.app
"baseUrl": ""
for
"baseUrl": ""
Hi all,
This thread was opened a while ago.
The tsconfig file is what determines what TS files are compiled. The error you are getting means that the files mentioned are not being compiled as explained in the following comment https://github.com/angular/angular-cli/issues/8284#issuecomment-341417325.
Having all the feedback in a single thread makes it hard to get meaningful reports, or to inform people of what versions the regressions that affect them were fixed.
Having so many hidden comments makes it hard for people to find the information in anything but the latest comments. But on the other hand I don't think most people would go through all of the comments anyway. New users that see this thread mostly read the first and latest comments and lose things said in between.
So for the reasons stated above (high volume of comments, hidden comments, hard to report and inform people) I'm also locking this issue to prevent this comment from being lost as new comments come in.
If you are still experiencing an issue please open a new issue, provide a simple repository reproducing the problem, and describe the difference between the expected and current behavior.