文件被vs代码锁定

时间:2019-04-20 13:29:25

标签: visual-studio-code

当我使用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代码,我找不到其他解决方案。 我不知道这是否是错误。

版本:

vs代码:1.33.1

操作系统:Windows_NT x64 10.0.17763

2 个答案:

答案 0 :(得分:0)

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

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

通过使用“ Lock Hunter”,您可以通过勾选右上角的“更多详细信息”对勾来查看哪个vs代码扩展名锁定了文件。

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

答案 1 :(得分:0)

从此chineese blog(重复on this other one)开始, 我猜想,一种解决方案是使用VScode settings.json配置,从vscode文件查看器中排除 win-unpacked 子文件夹和文件:

{
  "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