Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Each build of an Angular library is missing random files in the output folder #15952

Closed
JGH153 opened this issue Oct 28, 2019 · 13 comments · Fixed by #16340
Closed

Each build of an Angular library is missing random files in the output folder #15952

JGH153 opened this issue Oct 28, 2019 · 13 comments · Fixed by #16340
Assignees
Labels
area: @schematics/angular freq1: low Only reported by a handful of users who observe it rarely severity3: broken type: bug/fix
Milestone

Comments

@JGH153
Copy link

JGH153 commented Oct 28, 2019

🐞 Bug report

Command (mark with an x)

- [ ] new
- [x] build
- [ ] serve
- [ ] test
- [ ] e2e
- [ ] generate
- [ ] add
- [ ] update
- [ ] lint
- [ ] xi18n
- [ ] run
- [ ] config
- [ ] help
- [ ] version
- [ ] doc

Is this a regression?

First time creating library myself, but I have never seen this bug in other libraries.

Description

Each run of my library (ng build hal-components) (my library) is missing random files in the dist/hal-components/lib folder. A few runs gives me all files, but most (ca 90%) is missing several files. The files missing changes on each run.

Restarting the computer temporarily solves the problem, but it returns after a few hours to one days of use without a restart

Still get the bug if I stop the ng serve command on the consuming project. I get the bug both with, and without the watch flag.

This bug is really annoying as I need to manually check if all files are present before publishing to NPM.

🔬 Minimal Reproduction

Library is still tiny so I can link to it:
https://github.com/hafslundnett/hal-components/tree/build-bug
Only getting the bug on Windows (also tested on Mac, but did not get the bug).

Bug is periodic, but what I do is:

  1. yarn
  2. ng build hal-components
  3. Check the dist/hal-components/lib for missing components from the library

🔥 Exception or Error

There is no error, just random missing files.

🌍 Your Environment


Angular CLI: 8.3.12
Node: 10.16.0
OS: win32 x64
Angular: 8.1.3
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Package                            Version
------------------------------------------------------------
@angular-devkit/architect          0.801.3
@angular-devkit/build-angular      0.801.3
@angular-devkit/build-ng-packagr   0.801.3
@angular-devkit/build-optimizer    0.801.3
@angular-devkit/build-webpack      0.801.3
@angular-devkit/core               8.3.12
@angular-devkit/schematics         8.3.12
@angular/cdk                       8.2.3
@angular/cli                       8.3.12
@angular/material                  8.2.3
@ngtools/webpack                   8.1.3
@schematics/angular                8.3.12
@schematics/update                 0.803.12
ng-packagr                         5.7.0
rxjs                               6.4.0
typescript                         3.4.5
webpack                            4.35.2

Anything else relevant?
Running the latest version of Windows 10 Enterprise.

I understand this will be hard to solve, so I appreciate any workaround as a solution if anyone has a suggestion.

@JGH153 JGH153 changed the title Each build of a Angular library is missing random files in the output on Windows 10 Each build of a Angular library is missing random files in the output folder on Windows 10 Oct 28, 2019
@JGH153 JGH153 changed the title Each build of a Angular library is missing random files in the output folder on Windows 10 Each build of a Angular library is missing random files in the output folder Oct 28, 2019
@JGH153 JGH153 changed the title Each build of a Angular library is missing random files in the output folder Each build of an Angular library is missing random files in the output folder Oct 28, 2019
@alan-agius4
Copy link
Collaborator

@JGH153, I tried to take a look at this add did several runs with the reproduction you provided by I always managed to get 12 component files.

c:\git\cli-repos\hal-components (trunk -> origin)
λ ng build hal-components && ls -R | grep '.*[.]component.js' | wc -l
Building Angular Package

------------------------------------------------------------------------------
Building entry point '@hafslundnett/hal-components'
------------------------------------------------------------------------------
Compiling TypeScript sources through ngc
Bundling to FESM2015
Bundling to FESM5
Bundling to UMD
Minifying UMD bundle
Copying declaration files
Writing package metadata
Built @hafslundnett/hal-components

------------------------------------------------------------------------------
Built Angular Package!
 - from: c:\git\cli-repos\hal-components\projects\hal-components
 - to:   c:\git\cli-repos\hal-components\dist\hal-components
------------------------------------------------------------------------------

12

I am too running on a windows machine.

@alan-agius4
Copy link
Collaborator

What I am seeing strange is that if one of the files is missing the build will fail because to generate the FESM 2015 and FESM 5 bundles all files needs to be on disk.

I am thinking that you might be having a background process that is deleting the files after the build. Maybe a too strict anti-virus or something along this source.

@JGH153
Copy link
Author

JGH153 commented Oct 29, 2019

Ok so the missing files needs to be present during the build step for it to work. That's a really helpful clue. Never had my anti-virus delete files like that, but I’ll give it a try. And I’ll also terminate any other processes that potentially can delete the files and see if the problems persists.

@dummdidumm
Copy link

dummdidumm commented Oct 30, 2019

I have the same problem sometimes. In my case, most of the time it's some random files under lib (the definition files) that are missing, bundles/esm/fesm seem to be ok. I also have the feeling that the problem occurs more often with files nested in folders.

Example:

lib
   checkbox
       checkbox.component.d.ts // <- this file is present more often ...
       checkbox-with-label  // <- ... than this folder and its sub-files
           checkbox-with-label.component.d.ts

This problem also occurs when doing the build in watch mode. The files that are missing in watch mode will not get built as long as you don't touch them manually (do some changes to the file), so for me it seems that the cli just misses them out until someone points them out to it again.

@alan-agius4
Copy link
Collaborator

@dummdidumm can you please elaborate a bit more on the below statement.

The files that are missing in watch mode will not get built as long as you don't touch them manually (do some changes to the file), so for me it seems that the cli just misses them out until someone points them out to it again.

@alan-agius4 alan-agius4 added the needs: more info Reporter must clarify the issue label Oct 31, 2019
@dummdidumm
Copy link

@dummdidumm can you please elaborate a bit more on the below statement.

The files that are missing in watch mode will not get built as long as you don't touch them manually (do some changes to the file), so for me it seems that the cli just misses them out until someone points them out to it again.

When a file is not part of the output under lib in watch mode, this file will not appear in the output as long as you don't touch the file. So if I for example change code or make a comment in that file and then save that file, only then will that file appear in the output, not sooner.

The situation of not having all files under lib occurs more often if i have my main app running (ng serve), which gets some files from the lib which is then (re)built. Also I feel that when I have VS Code open for some time the chance increases of that happening. So maybe it's processes watching/touching/locking files (VS Code, Angular Language Service, ng serve, ng build --project=my-lib --watch) that conflict with each other?

I also sometimes get "operation not permitted"-errors like this when trying to build the library, maybe this is related:

BUILD ERROR
EPERM: operation not permitted, unlink 'C:\repos\rotec-components\dist\rotec-components\lib\action-menu'
Error: EPERM: operation not permitted, unlink 'C:\repos\rotec-components\dist\rotec-components\lib\action-menu'

EPERM: operation not permitted, unlink 'C:\repos\rotec-components\dist\rotec-components\lib\action-menu'
Error: EPERM: operation not permitted, unlink 'C:\repos\rotec-components\dist\rotec-components\lib\action-menu'

npm error log:

0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli   'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   'run',
1 verbose cli   'watch' ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'prewatch', 'watch', 'postwatch' ]
5 info lifecycle [email protected]~prewatch: [email protected]
6 info lifecycle [email protected]~watch: [email protected]
7 verbose lifecycle [email protected]~watch: unsafe-perm in lifecycle true
8 verbose lifecycle [email protected]~watch: PATH: <- took out because of privacy reasons ->
9 verbose lifecycle [email protected]~watch: CWD: C:\repos\rotec-components
10 silly lifecycle [email protected]~watch: Args: [ '/d /s /c', 'ng build --project=rotec-components --watch' ]
11 silly lifecycle [email protected]~watch: Returned: code: 1  signal: null
12 info lifecycle [email protected]~watch: Failed to exec watch script
13 verbose stack Error: [email protected] watch: `ng build --project=rotec-components --watch`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\index.js:301:16)
13 verbose stack     at EventEmitter.emit (events.js:182:13)
13 verbose stack     at ChildProcess.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:182:13)
13 verbose stack     at maybeClose (internal/child_process.js:962:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:251:5)
14 verbose pkgid [email protected]
15 verbose cwd C:\repos\rotec-components
16 verbose Windows_NT 10.0.17763
17 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "watch"
18 verbose node v10.15.0
19 verbose npm  v6.4.1
20 error code ELIFECYCLE
21 error errno 1
22 error [email protected] watch: `ng build --project=rotec-components --watch`
22 error Exit status 1
23 error Failed at the [email protected] watch script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

@JGH153
Copy link
Author

JGH153 commented Nov 1, 2019

Found the cause of the bug. I get missing files 100% of the time when I use the Angular language service plugin for vscode AND have one or more files in the library open during a build of the library (for example app-shell). Disabling the plugin gives all files always after more than 20 runs. Should I file this issue with vscode-ng-language-service?

@JGH153
Copy link
Author

JGH153 commented Nov 1, 2019

Seems to be a well known bug: ng-packagr/ng-packagr#837 (comment)

Adding "exclude": ["dist"] to tsconfig and running the library build/watch from a terminal with administrative privileges seems like it solved the problem with missing files and the language service

@dummdidumm
Copy link

If part of the problem (if not all) is solved by adding dist to exclude, maybe the angular-cli could add this to the tsconfig.json (lib/app/root) by default?

@JGH153
Copy link
Author

JGH153 commented Nov 4, 2019

The workaround was more stable, but broke down as well in the end. Had to disable the plugin

@alan-agius4 alan-agius4 removed the needs: more info Reporter must clarify the issue label Nov 5, 2019
@alan-agius4
Copy link
Collaborator

We definitely should exclude dist

@alan-agius4 alan-agius4 added area: @schematics/angular freq1: low Only reported by a handful of users who observe it rarely severity3: broken type: bug/fix labels Nov 5, 2019
@ngbot ngbot bot added this to the Backlog milestone Nov 5, 2019
@alan-agius4 alan-agius4 self-assigned this Nov 5, 2019
@kyliau
Copy link
Contributor

kyliau commented Dec 3, 2019

This should have been fixed with the latest v0.900.0 extension, which is already published.
The env flag TSC_NONPOLLING_WATCHER is now enforced, and it should not lock up the fs anymore.

This issue has the same underlying root cause as angular/vscode-ng-language-service#224, which is now closed.

@kyliau kyliau closed this as completed Dec 3, 2019
mgechev pushed a commit that referenced this issue Dec 3, 2019
Currently the library schematic doesn't support adding a secondary entry-point and having deep imports is not recommanded.

It's best if paths are more stricter when having a secondary entry-point instead of a wildcard.

Instead of :
```
"lib/*": [
  "dist/lib/*"
]
```

Users should configure:
```
"lib/secondary": [
  "dist/lib/secondary"
]
```

This would allow a better DX experience when using auto imports in IDE's.

Closes: #15952
mgechev pushed a commit that referenced this issue Dec 4, 2019
Currently the library schematic doesn't support adding a secondary entry-point and having deep imports is not recommanded.

It's best if paths are more stricter when having a secondary entry-point instead of a wildcard.

Instead of :
```
"lib/*": [
  "dist/lib/*"
]
```

Users should configure:
```
"lib/secondary": [
  "dist/lib/secondary"
]
```

This would allow a better DX experience when using auto imports in IDE's.

Closes: #15952
@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Jan 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: @schematics/angular freq1: low Only reported by a handful of users who observe it rarely severity3: broken type: bug/fix
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants