I have two libraries for my app: contact-us
and about-us
.
Contact-us
is perfectly linked to my app, but when I use the same approach to link about-us
, I get some errors!.
What I've done to link about-us
:
cd libraries/about-us/
npm run build
cd /dist/about-us
npm link
ng build --watch
What I get after ng build --watch
(please notice points 1, 2 and 3!):
Building Angular Package
------------------------------------------------------------------------------
Building entry point 'about-us'
------------------------------------------------------------------------------
// Point 1. this error is also shown for contact-us, but doesn't make problem
⠋ Compiling with Angular sources in Ivy partial compilation mode.internal/bootstrap/switches/does_own_process_state.js:130
cachedCwd = rawMethods.cwd();
^
Error: ENOENT: no such file or directory, uv_cwd
at process.wrappedCwd [as cwd] (internal/bootstrap/switches/does_own_process_state.js:130:28)
at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:872:42)
at Loader.resolve (internal/modules/esm/loader.js:89:40)
at Loader.getModuleJob (internal/modules/esm/loader.js:242:28)
at Loader.import (internal/modules/esm/loader.js:177:28)
at internal/modules/run_main.js:52:28
at Object.loadESM (internal/process/esm_loader.js:68:11)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async handleMainPromise (internal/modules/run_main.js:59:12) {
errno: -2,
code: 'ENOENT',
syscall: 'uv_cwd'
}
//point 2. this error is not shown for contact-us.
//point 3. if I interrupt the command in this point, I can still see files in dist/about-us/
events.js:377
throw er; // Unhandled 'error' event
^
Error: ENOENT: no such file or directory, uv_cwd
at process.cwd (internal/main/worker_thread.js:149:19)
at MessagePort.<anonymous> (internal/main/worker_thread.js:163:48)
at MessagePort.[nodejs.internal.kHybridDispatch] (internal/event_target.js:399:24)
at MessagePort.exports.emitMessage (internal/per_context/messageport.js:18:26)
Emitted 'error' event on process instance at:
at emitUnhandledRejectionOrErr (internal/event_target.js:579:11)
at MessagePort.[nodejs.internal.kHybridDispatch] (internal/event_target.js:403:9)
at MessagePort.exports.emitMessage (internal/per_context/messageport.js:18:26)
at Worker.[kOnExit] (internal/worker.js:271:5)
at Worker.<computed>.onexit (internal/worker.js:203:20) {
errno: -2,
code: 'ENOENT',
syscall: 'uv_cwd'
}
I noticed that, after this, the dist
directory gets empty and the project folder inside it is deleted! And I think this is the reason of ENOENT
error.
After a bit search, I found here that ng build --watch
looks for dist
directory, so I ran it not in the about-us/dist/about-us
but in the root about-us
.
Then I don't get any error by ng build --watch
.
However, when in my app directory I ran:
npm link about-us
ionic cap build android
my app is not able to find the library, and I get:
cannot find module 'about-us' or its corresponding type declarations.
29 loadChildren: () => import('about-us').then(m => m.AboutusModule)
~~~~~~~~~~~~~~~~
[ERROR] An error occurred while running subprocess ng.
ng run app:build exited with exit code 1.
Also when I check my app's node_modules
directory, I can see that the created link for about-us
is different than the link for contact-us
.
So I think I have to understand why ng build --watch
is not working as expected!
Does any one know what is the problem and how I can fix it? Thank you in advance!
Some info: I'm using nvm14.20 and cli 14.0.1.
I found what was the problem. Yes ng build --watch
looks for dist
directory, so shouldn't be run inside dist
, but npm link
must be run in dist\about-us
so the solution is:
npm run build
cd /dist/about-us
npm link
cd ../..
ng build --watch