When I use electron-builder
package to build my electron app, vs code throws the Error:
⨯ 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/[email protected]+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! [email protected] build: `node .Shorthands_PC/build.js && electron-builder`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] 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
I can't find any solution apart from closing VS Code. I don't know if it's a bug.
version:
vs code: 1.33.1
os: Windows_NT x64 10.0.17763
A solution consist in excluding win-unpacked subfolders and files from vscode file watcher, using this VScode settings.json
configuration:
{
"files.watcherExclude": {
"**/build/win-unpacked/**": true
}
}
this can be configured per project from vscode using following menus, not forgeting to then restart VScode:
/file/Preferences/Settings/Workspace/Text Editor/Files/Exclude/Add Pattern
which will update ./.vscode/settings.json of current VScode project directory as described above. this github thread also have it explained.
... check the effective location of your asar file:
In my case, the asar file is located under ./dist/win-unpacked/resources/app.asar
I thus configured the files.watcherExclude to
"**/dist/win-unpacked/**":true
Solution guessed from this chineese blog (repeated on this other one).
You may use "Lock Hunter" from https://lockhunter.com/ to see the file is being locked by which processes.
Sometime it could be some vs code extension.
By using "Lock Hunter", you can see which vs code extension locks the file by ticking "More details" tick at the top right corner.
For me I found it "Image preview" extension locks the file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With