我的应用程序有两个库:
contact-us
和 about-us
。
Contact-us
完美链接到我的应用程序,但是当我使用相同的方法链接 about-us
时,我得到了一些错误!.
我为链接所做的工作
about-us
:
cd libraries/about-us/
npm run build
cd /dist/about-us
npm link
ng build --watch
ng build --watch
之后我得到了什么(请注意第1、2和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'
}
我注意到,在此之后,
dist
目录变空了,其中的项目文件夹被删除了!我认为这就是ENOENT
错误的原因。
经过一番搜索,我发现here
ng build --watch
寻找dist
目录,所以我不在about-us/dist/about-us
中运行它,而是在根about-us
中运行它。
然后我没有得到任何错误ng build --watch
.
但是,当我在我的应用程序目录中运行时:
npm link about-us
ionic cap build android
我的应用找不到图书馆,我得到:
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.
此外,当我检查我的应用程序的
node_modules
目录时,我可以看到为 about-us
创建的链接与 contact-us
的链接不同。
所以我想我必须明白为什么
ng build --watch
没有按预期工作!
有谁知道问题出在哪里以及我该如何解决?提前谢谢你!
一些信息: 我正在使用 nvm14.20 和 cli 14.0.1.
我发现了问题所在。是的
ng build --watch
寻找dist
目录,所以不应该在dist
内运行,但是npm link
必须在dist\about-us
中运行所以解决方案是:
npm run build
cd /dist/about-us
npm link
cd ../..
ng build --watch