NG-PACKAGR:构建错误 EPERM:不允许操作



我按照Nikolas LeBlanc的本教程构建了一个Angular 4组件库。本教程介绍了一种在另一个项目中重用模块的方法,方法是打包一个项目并将其安装在另一个项目中。

首先,这是我的软件版本:

  • 视窗 10 专业版:1709 内部版本 16299.371
  • 角度IDE: 17.0.0.c0000019t201804160508
  • ng-packagr: 2.4.2
  • @angular/*: 5.2.10
  • 打字稿:2.5.3
  • RXJS:5.5.10
  • 节点:9.4.0
  • NPM:5.6.0

除了标题"创建我们的包"之外,我无法进一步遵循教程,因为执行以下命令:

ng-packagr -p ng-package.json

执行此命令时,将发生以下错误:

npm run forestrun
bte@0.0.0 forestrun C:UsersKevin.DeGoedeDocumentsyoyobte
ng-packagr -p ng-package.json
Building Angular Package
Building entry point 'bte'
Cleaning build directory
Rendering Stylesheets
Rendering Templates
Compiling TypeScript sources through ngc
Bundling to FESM15
Bundling to FESM5
Bundling to UMD
Minifying UMD bundle
Relocating source maps
Copying staged files
Writing package metadata
Distributing npm packages with 'dependencies' is not recommended. Please consider adding to 'peerDependencies' or remove it from 'dependencies'.
BUILD ERROR
EPERM: operation not permitted, unlink 'C:UsersKevinDocumentsyoyobtedistsrcappmodules'
Error: EPERM: operation not permitted, unlink 'C:UsersKevinDocumentsyoyobtedistsrcappmodules'
npm ERR! code ELIFECYCLE
npm ERR! errno 111
npm ERR! bte@0.0.0 forestrun: ng-packagr -p ng-package.json
npm ERR! Exit status 111
npm ERR!
npm ERR! Failed at the bte@0.0.0 forestrun script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:UsersKevinAppDataRoamingnpm-cache_logs2018-05-04T08_30_30_818Z-debug.log

重试时,出现以下错误:

npm run forestrun
bte@0.0.0 forestrun C:UsersKevinDocumentsyoyobte
ng-packagr -p ng-package.json
Building Angular Package
glob error { Error: EPERM: operation not permitted, scandir 'C:UsersKevinDocumentsyoyobtedistsrcappmodules'
errno: -4048,
code: 'EPERM',
syscall: 'scandir',
path: 'C:UsersKevinDocumentsyoyobtedistsrcappmodules' }
BUILD ERROR
EPERM: operation not permitted, scandir 'C:UsersKevinDocumentsyoyobtedistsrcappmodules'
Error: EPERM: operation not permitted, scandir 'C:UsersKevinDocumentsyoyobtedistsrcappmodules'
npm ERR! code ELIFECYCLE
npm ERR! errno 111
npm ERR! bte@0.0.0 forestrun: ng-packagr -p ng-package.json
npm ERR! Exit status 111
npm ERR!
npm ERR! Failed at the bte@0.0.0 forestrun script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:UsersKevinAppDataRoamingnpm-cache_logs2018-05-04T08_54_07_739Z-debug.log

我也在我的Mac上尝试过,但一切正常,但我们都在Windows机器上工作。那么我怎样才能让ng-packagr在我的Windows机器上工作呢?

您可以尝试代表管理员运行命令行。也许会有所帮助

如果某些东西锁定了文件/目录,通常会发生这种情况。对我来说,通常VS Code这样做。

防止此错误的一种方法是 [1] 在管理员模式下运行(如其他答案中建议的那样),或 [2] 关闭 VS Code 并尝试

或者 [3] 从tsconfig.json中排除目录

"exclude": [
"dist"
]

清空工作区的dist文件夹。它对我有用。

我意识到我的应用程序处于中断点...... 只需停止应用程序运行,您就会很好。

自行安装出现错误的模块。

在花费大量时间并尝试所有可能的建议后,我发现安装错误提到的特定模块全局解决了该问题:

例如:npm ERR!{ 错误:EPERM:不允许操作,取消链接'C:\Path\Docume nts\AngularProjects\my-sample-app333ode_modules.staging@angular\core-a3d1aa4 8\bundles\core.umd.js

我运行:npm install -global @angular/core

它为我修复了它!最后!!

就我而言,删除"Angular 语言服务"插件对我有帮助。

我在这里找到了这个解决方案。

最新更新