Ionic ng build --watch删除dist中的项目目录

d5vmydt9  于 2023-05-05  发布在  Ionic
关注(0)|答案(1)|浏览(196)

我的应用程序有两个库:contact-usabout-usContact-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错误的原因。
经过一点搜索,我发现hereng 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。

ulmd4ohb

ulmd4ohb1#

我找到问题所在了。是的,ng build --watch查找dist目录,所以不应该在dist中运行,但是npm link必须在dist\about-us中运行,所以解决方案是:

npm run build
cd /dist/about-us
npm link  
cd ../..
ng build --watch

相关问题