Repository navigation
Description
🐞 Bug report
Command (mark with an x)
- build
Is this a regression?
Unknown. I am in the process of updating from Angular 10.x (where things build fine) to 13.x (where things are breaking), but it's unclear if this is a regression.
Description
I have two Angular library projects in a monorepo. Project B depends on Project A. Both are pretty small. When attempting to build both, Project A builds successfully but Project B fails with the following error:
Schema validation failed with the following errors:
Data path "/error" must be string.
It's unclear what schema the error is referring to and it's also unclear what Data path "/error" is referring to. If "schema" refers to angular.json in this context, it's unclear what Data path "/error" is referring to since an "error" key isn't documented for angular.json.
🔬 Minimal Reproduction
Clone the angular-cli-build-bug branch of my service-work/is-loading repo. The repo contains a .devcontainer.json file which can be used to quickly setup the dev environment.
- run
yarn install - (optional) run
yarn test. Tests should all pass. - run
yarn build. The@service-work/is-loadingproject should build successfully but the@service-work/scroll-positionlibrary should fail with the following message:Schema validation failed with the following errors: Data path "/error" must be string.
Note that the @service-work/scroll-position package depends on the @service-work/is-loading package. However, the only file in @service-work/scroll-position that actually imports from @service-work/is-loading is the projects/scroll-position/src/scroll-position/module/directive/scroll-position.directive.ts file. If you comment out the @service-work/is-loading import in that file, as well as the related code, then the @service-work/scroll-position file builds without error.
It's unclear if there's something wrong in my code which is preventing the project from building (in which case the provided error message should be improved to make clear what the problem is) or if there's a bug with the build script.
🔥 Exception or Error
Schema validation failed with the following errors:
Data path "/error" must be string.
🌍 Your Environment
Angular CLI: 13.2.2
Node: 12.22.7
Package Manager: yarn 1.22.15
OS: linux x64
Angular: 13.2.1
... animations, common, compiler, compiler-cli, core
... language-service, platform-browser, platform-browser-dynamic
... router
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1302.2
@angular-devkit/build-angular 13.2.2
@angular-devkit/core 13.2.2
@angular-devkit/schematics 13.2.2
@angular/cli 13.2.2
@schematics/angular 13.2.2
ng-packagr 13.2.1
rxjs 6.6.7
typescript 4.5.5
Anything else relevant?
- This repo is managed as a Yarn 1.x workspace.
- I don't think this is actually relevant, but I'll mention that my development computer is a M1 Pro Macbook Pro that is running an
x86_64devcontainer using qemu.
Activity
alan-agius4 commentedon Feb 7, 2022
There are two parts of this problem.
misconfiguration
The root cause of the error is that the project is misconfigured. The TypeScript compiler is unable to resolve
@service-work/is-loading. This can be resolved by setting as path mappings in your tsconfig.compiler-cli
The compiler-cli is surfacing this particular error as a
FatalDiagnosticError, which should not happen and therefore this is also an issue in the compiler-cli, which should converted this to ats.Diagnosticinternally.[-]`Data path "/error" must be string` build failure[/-][+]FatalDiagnosticError is being throw instead of it being converted to a`ts.Diagnostic`[/+][-]FatalDiagnosticError is being throw instead of it being converted to a`ts.Diagnostic`[/-][+]`FatalDiagnosticError` is being throw instead of it being converted to a`ts.Diagnostic`[/+]jorroll commentedon Feb 8, 2022
Thanks for tracking this down alan-agius! I can confirm that adding
{ "compilerOptions": { ... "paths": { "@service-work/is-loading": ["projects/is-loading/build"] } } }Does fix the build problem. I'm surprised that it is needed though. Already, because this is a yarn workspace, both
@service-work/is-loadingand@service-work/scroll-positionare symlinked in thenode_modulesfolder (though the symlinks point to the raw source rather than the "build" output). It's for this reason that the tests run without error when thescroll-positionlibrary imports theis-loadinglibrary. Why is the "build" version ofis-loadingneeded in order to buildscroll-position? Is this documented somewhere? Sinceis-loadingis a peer dependency, it's not being included inscroll-positionanyway and so, I expected, it was only used for typings during the build process.As an aside, it's strange but I never got a notification that a comment was added to this issue (I've looked back through all my recently "done" notifications and confirmed that nothing exists for this issue). I wonder if it's related to the fact that the issue was moved from one repo to another.
IanTheG commentedon Feb 9, 2022
I was having a similar issue when trying to build my shared-components library when also using an Angular workspace to hold a few Angular apps. Unlike the
@service-work/is-loadingand@service-work/scroll-positionpackages, I wanted my library to only be used locally.I'm also using Angular 13.2.
The error was caused by two things (that I think only happened because I was using a workspace):
public-api.tsfile was contained within aprojectsfolder that lived adjacently to thelibfolder and insidesrcpublic-api.tsfile were incorrect, giving the errorCannot find module... or its corresponding type declarationserrorMoving the file outside the folder, correcting the exports, and renaming the
entryFilefield in the ng-package.json solved the issue. For me, no other changes to ts.config.json files were needed.To use my library, I first built it using
ng build shared-components --watchand then imported into my module like this:Then I can use any component, service, etc. in any place in my app!
I'm not sure why Angular would generate the public-api.ts file inside a folder when using workspaces. I'd hoped to have it work out the box, but it cost me an hour or two of problem solving.
jorroll commentedon Feb 10, 2022
@IanTheG It's a little unclear because you haven't included a reproduction, but it sounds like you are providing another example of a (different) error message being suppressed by the compiler-cli. It sounds like this is also incorrectly resulting in a
FatalDiagnosticErroras described by alan-agius above.Personally, I find this comment to be confusing. You seem to be implying that, because a file named
public-api.tsis inside a folder your build was failing. But, in theory, so long as the relevant configuration files are setup correctly (i.e.angular.json,tsconfig.json,ng-package.json, etc), a library's entry file namedpublic-api.ts(or something else, because it can be named anything) should have no problem being located inside a folder. If you look at my Angular IsLoadingService repo (which, thanks to alen-arguis' help, is now building properly), you'll see that the entry points for the libraries are located within folders. If you're saying that you generated a new angular library using the CLI, and that new library was not generated with the proper configuration, that sounds like a separate issue.PhiLhoSoft commentedon Feb 14, 2022
@alan-agius4, is there a way to get a dump of FatalDiagnosticError object, like you show?
I have the same error, probably hiding some other error, and I would like to fix the problem without waiting for the next release.
Thank you.
alan-agius4 commentedon Feb 14, 2022
@PhiLhoSoft, you can add a console log or breakpoint here: https://github.com/angular/angular-cli/blob/e1d9b5b447b67c028e84fd764e4ae390300f92a7/packages/angular_devkit/build_angular/src/builders/ng-packagr/index.ts#L61
PhiLhoSoft commentedon Feb 14, 2022
Thanks.
I translated it to:
<project>/node_modules/@angular-devkit/build-angular/src/builders/ng-packagr/index.jsAnd I changed it as follows:
(line 61)
I got an error, but it remains cryptic (Unable to import symbol AddressbookAvatarComponent; this symbol was imported OK before…)
That's a problem I had in the past (Angular 11 I think), not sure why it resurfaced.
I fear I can't provide a reproduction, so I am on my own.
Thanks anyway, it was useful!
PhiLhoSoft commentedon Mar 4, 2022
Update: I had this error after adding a component to the library project.
I had another look at the component, and finally spotted the culprits: I routinely import classes by typing their name, then hitting Enter on the suggestion made by VSC.
But I didn't see it made
import { SomeClass } from 'api';where there is no definition of thisapithing.It should have been
import { SomeClass } from 'the-current-project/api';because intsconfig.json, I defined in thepathssection:'the-current-project/*': ['./*'],And then, it worked…
Note 1: the
'Unable to import symbol AddressbookAvatarComponent.'message is totally unrelated to the new component which doesn't use this one. This is why it was hard to track…Note 2: beware, sometime VSC also makes
import { Foo ] from '../';(orfrom './';) because there is anindex.tsfile at this location (it is used to export models, services, modules, components, etc. Barrel files.). These imports creates subtle bugs too, perhaps cyclic dependencies. Change them toimport { Foo ] from '../foo.ts';for example.kkoo95 commentedon May 4, 2022
So is it some kind of regression ? TS path mapping must point to build library directory no matter what ? Has it always be liked this ? Isn't Nx capable of something like this ? What's the magic behind it then ? (so many questions...)
A future use case to this is being capable of mapping to symlinked sources. This could be really helpful for companies which have lots of separated VCS repo but where all those projects need each other (hence mimicking some kind of monorepo)
fix(compiler-cli): use inline type-check blocks for components outsid…
fix(compiler-cli): use inline type-check blocks for components outsid…
angular-automatic-lock-bot commentedon Jul 11, 2022
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.