【问题标题】:File is locked by VS Code (Visual Studio Code)文件被 VS Code (Visual Studio Code) 锁定
【发布时间】:2019-09-10 10:37:13
【问题描述】:

当我使用electron-builder 包构建我的电子应用程序时,vs 代码抛出错误:

 ⨯ remove D:\project\Shorthands_PC\build\win-unpacked\resources\app.asar: The process cannot access the file because it is being used by another process.
github.com/develar/go-fs-util.EnsureEmptyDir
        /Volumes/data/go/pkg/mod/github.com/develar/go-fs-util@v2.0.1-0.20181113101504-f6630ccc0e93+incompatible/fs.go:101
github.com/develar/app-builder/pkg/electron.unpackElectron.func1.1
        /Volumes/data/Documents/app-builder/pkg/electron/electronUnpack.go:39
github.com/develar/app-builder/pkg/util.MapAsyncConcurrency.func2
        /Volumes/data/Documents/app-builder/pkg/util/async.go:67
runtime.goexit
        /usr/local/Cellar/go/1.12/libexec/src/runtime/asm_amd64.s:1337

Error: D:\project\Shorthands_PC\node_modules\app-builder-bin\win\x64\app-builder.exe exited with code 1
    at ChildProcess.childProcess.once.code (D:\project\Shorthands_PC\node_modules\builder-util\src\util.ts:244:14)
    at Object.onceWrapper (events.js:273:13)
    at ChildProcess.emit (events.js:182:13)
    at maybeClose (internal/child_process.js:961:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:248:5)
From previous event:
    at _unpack (D:\project\Shorthands_PC\node_modules\app-builder-lib\out\electron\ElectronFramework.js:298:18)
    at unpack (D:\project\Shorthands_PC\node_modules\app-builder-lib\out\electron\ElectronFramework.js:257:18)
    at ElectronFramework.prepareApplicationStageDirectory (D:\project\Shorthands_PC\node_modules\app-builder-lib\src\electron\ElectronFramework.ts:125:12)
    at D:\project\Shorthands_PC\node_modules\app-builder-lib\src\platformPackager.ts:180:21
    at Generator.next (<anonymous>)
From previous event:
    at WinPackager.doPack (D:\project\Shorthands_PC\node_modules\app-builder-lib\src\platformPackager.ts:167:165)
    at D:\project\Shorthands_PC\node_modules\app-builder-lib\src\platformPackager.ts:113:16
    at Generator.next (<anonymous>)
From previous event:
    at WinPackager.pack (D:\project\Shorthands_PC\node_modules\app-builder-lib\src\platformPackager.ts:111:95)
    at D:\project\Shorthands_PC\node_modules\app-builder-lib\src\packager.ts:430:24
    at Generator.next (<anonymous>)
    at xfs.stat (D:\project\Shorthands_PC\node_modules\fs-extra-p\node_modules\fs-extra\lib\mkdirs\mkdirs.js:56:16)
    at D:\project\Shorthands_PC\node_modules\graceful-fs\polyfills.js:285:20
    at FSReqWrap.oncomplete (fs.js:159:5)
From previous event:
    at Packager.doBuild (D:\project\Shorthands_PC\node_modules\app-builder-lib\src\packager.ts:396:24)
    at D:\project\Shorthands_PC\node_modules\app-builder-lib\src\packager.ts:366:57
    at Generator.next (<anonymous>)
    at D:\project\Shorthands_PC\node_modules\graceful-fs\graceful-fs.js:111:16
    at D:\project\Shorthands_PC\node_modules\graceful-fs\graceful-fs.js:45:10
    at FSReqWrap.oncomplete (fs.js:145:20)
From previous event:
    at Packager._build (D:\project\Shorthands_PC\node_modules\app-builder-lib\src\packager.ts:335:133)
    at D:\project\Shorthands_PC\node_modules\app-builder-lib\src\packager.ts:331:23
    at Generator.next (<anonymous>)
    at runCallback (timers.js:696:18)
    at tryOnImmediate (timers.js:667:5)
    at processImmediate (timers.js:649:5)
From previous event:
    at Packager.build (D:\project\Shorthands_PC\node_modules\app-builder-lib\src\packager.ts:288:14)
    at build (D:\project\Shorthands_PC\node_modules\app-builder-lib\src\index.ts:59:28)
    at build (D:\project\Shorthands_PC\node_modules\electron-builder\src\builder.ts:228:10)
    at then (D:\project\Shorthands_PC\node_modules\electron-builder\src\cli\cli.ts:46:19)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! Shorthands_PC@1.0.0 build: `node .Shorthands_PC/build.js && electron-builder`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the Shorthands_PC@1.0.0 build 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:\Users\guoxiaoshen\AppData\Roaming\npm-cache\_logs\2019-04-20T13_14_41_734Z-debug.log

除了关闭 VS Code,我找不到任何解决方案。 不知道是不是bug。

版本:

vs 代码:1.33.1

操作系统:Windows_NT x64 10.0.17763

【问题讨论】:

  • 你解决过这个问题吗?真的很烦!

标签: visual-studio-code electron-builder


【解决方案1】:

解决方案包括从 vscode 文件观察器中排除 win-unpacked 子文件夹和文件,使用此 VScode settings.json 配置:

{
  "files.watcherExclude": {
    "**/build/win-unpacked/**": true
  }
}

这可以使用以下菜单从 vscode 为每个项目进行配置, 不要忘记然后重新启动VScode:

/file/Preferences/Settings/Workspace/Text Editor/Files/Exclude/Add Pattern

这将更新当前 VScode 项目目录的 ./.vscode/settings.json ,如上所述。 this github thread也有解释。

...检查您的 asar 文件的有效位置: 就我而言,asar 文件位于./dist/win-unpacked/resources/app.asar 下 因此,我将 files.watcherExclude 配置为

"**/dist/win-unpacked/**":true

从这个chineese blog(重复on this other one)猜到的解决方案。

【讨论】:

    【解决方案2】:

    您可以使用https://lockhunter.com/ 的“Lock Hunter”查看文件被哪些进程锁定。

    有时可能是一些 vs 代码扩展。

    通过使用“Lock Hunter”,您可以通过勾选右上角的“More details”勾选来查看哪个vs代码扩展锁定了文件。

    对我来说,我发现“图像预览”扩展锁定了文件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-18
      • 1970-01-01
      • 2018-03-07
      • 1970-01-01
      • 1970-01-01
      • 2016-09-25
      • 1970-01-01
      • 2019-11-23
      相关资源
      最近更新 更多