electron-builder: Builder in 25.0.0 finds files outside project and throws error

25.0.0

20.11.0

31.2.1 (current)

All, but testing on mac

Building in 24.x didn’t have this problem. I tried to upgrade and have an issue where the filter is throwing an error about files it finds even though they’re outside the directory where the build is happening (and also have all the dependencies set to no-hoist and that also didn’t work)

      "**/electron-builder",
      "**/app-builder-lib",
      "**/builder-util",
      "**/builder-util-runtime",
      "**/dmg-builder",

Here’s the error stack for one iteration (I’ve tried a number of ways to do this. This stack is before I did nohoist. The question is: How can I set a relative directory for the file filter not to go above?

<PATH>/platform/build-dist/cloud/main/.env.cloud.defaults must be under <PATH>/platform/build-dist/desktop/main/app/
at getRelativePath (<PATH>/platform/node_modules/app-builder-lib/src/util/filter.ts:32:13)
    at AsarPackager.unpackPattern (<PATH>/platform/node_modules/app-builder-lib/src/util/filter.ts:57:22)
    at AsarPackager.createPackageFromFiles (<PATH>/platform/node_modules/app-builder-lib/src/asar/asarUtil.ts:130:82)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at AsarPackager.pack (<PATH>/platform/node_modules/app-builder-lib/src/asar/asarUtil.ts:50:41)
    at <PATH>/platform/node_modules/app-builder-lib/src/platformPackager.ts:439:11
    at async Promise.all (index 0)
    at AsyncTaskManager.awaitTasks (<PATH>/platform/node_modules/builder-util/src/asyncTaskManager.ts:65:25)
    at MacPackager.doPack (<PATH>/platform/node_modules/app-builder-lib/src/platformPackager.ts:293:5)
    at MacPackager.pack (<PATH>/platform/node_modules/app-builder-lib/src/macPackager.ts:201:9)
    at Packager.doBuild (<PATH>/platform/node_modules/app-builder-lib/src/packager.ts:458:9)
    at executeFinally (<PATH>/platform/node_modules/builder-util/src/promise.ts:12:14)
    at Packager.build (<PATH>/platform/node_modules/app-builder-lib/src/packager.ts:392:31)
    at executeFinally (<PATH>/platform/node_modules/builder-util/src/promise.ts:12:14)```

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 6
  • Comments: 16 (2 by maintainers)

Most upvoted comments

@mmaietta It appears to be an issue caused by electron/asar integration.

copy file config

  - from: src/renderer/libs/viewer
    to: out/renderer/libs/viewer
    filter:
      - '!**/*.{md,map,pdf}'
      - '!**/LICENSE'
      - '!**/*.{md,map,pdf}'
      - '!**/LICENSE'

error info

  ⨯ unable to copy, file is symlinked outside the package  source=src\renderer\libs\viewer\pdfjs\3.10.111\build\pdf.sandbox.js realPathFile=D:\Messenger\clients\packages\viewer\pdfjs\3.10.111\build\pdf.sandbox.js
  • async task error  error=Cannot copy file (pdf.sandbox.js) symlinked to file (pdf.sandbox.js) outside the package as that violates asar security integrity
  ⨯ unable to copy, file is symlinked outside the package  source=src\renderer\libs\viewer\pdfjs\3.10.111\build\pdf.worker.js realPathFile=D:\Messenger\clients\packages\viewer\pdfjs\3.10.111\build\pdf.worker.js
  • async task error  error=Cannot copy file (pdf.worker.js) symlinked to file (pdf.worker.js) outside the package as that violates asar security integrity
  ⨯ unable to copy, file is symlinked outside the package  source=src\renderer\libs\viewer\pdfjs\3.10.111\build\pdf.js realPathFile=D:\Messenger\clients\packages\viewer\pdfjs\3.10.111\build\pdf.js
  • async task error  error=Cannot copy file (pdf.js) symlinked to file (pdf.js) outside the package as that violates asar security integrity
  ⨯ unable to copy, file is symlinked outside the package  source=src\renderer\libs\viewer\pdfjs\3.10.111\web\cmaps\78-EUC-V.bcmap realPathFile=D:\Messenger\clients\packages\viewer\pdfjs\3.10.111\web\cmaps\78-EUC-V.bcmap
  • async task error  error=Cannot copy file (78-EUC-V.bcmap) symlinked to file (78-EUC-V.bcmap) outside the package as that violates asar security integrity
  ⨯ unable to copy, file is symlinked outside the package  source=src\renderer\libs\viewer\pdfjs\3.10.111\web\cmaps\78-EUC-H.bcmap realPathFile=D:\Messenger\clients\packages\viewer\pdfjs\3.10.111\web\cmaps\78-EUC-H.bcmap
  • async task error  error=Cannot copy file (78-EUC-H.bcmap) symlinked to file (78-EUC-H.bcmap) outside the package as that violates asar security integrity
  ⨯ unable to copy, file is symlinked outside the package  source=src\renderer\libs\viewer\pdfjs\3.10.111\web\cmaps\78-H.bcmap realPathFile=D:\Messenger\clients\packages\viewer\pdfjs\3.10.111\web\cmaps\78-H.bcmap
  • async task error  error=Cannot copy file (78-H.bcmap) symlinked to file (78-H.bcmap) outside the package as that violates asar security integrity
  ⨯ unable to copy, file is symlinked outside the package  source=src\renderer\libs\viewer\pdfjs\3.10.111\web\cmaps\78-RKSJ-H.bcmap realPathFile=D:\Messenger\clients\packages\viewer\pdfjs\3.10.111\web\cmaps\78-RKSJ-H.bcmap
  • async task error  error=Cannot copy file (78-RKSJ-H.bcmap) symlinked to file (78-RKSJ-H.bcmap) outside the package as that violates asar security integrity
  ⨯ unable to copy, file is symlinked outside the package  source=src\renderer\libs\viewer\pdfjs\3.10.111\web\cmaps\78-V.bcmap realPathFile=D:\Messenger\clients\packages\viewer\pdfjs\3.10.111\web\cmaps\78-V.bcmap
  • async task error  error=Cannot copy file (78-V.bcmap) symlinked to file (78-V.bcmap) outside the package as that violates asar security integrity
  ⨯ unable to copy, file is symlinked outside the package  source=src\renderer\libs\viewer\pdfjs\3.10.111\web\cmaps\78-RKSJ-V.bcmap realPathFile=D:\Messenger\clients\packages\viewer\pdfjs\3.10.111\web\cmaps\78-RKSJ-V.bcmap
  • async task error  error=Cannot copy file (78-RKSJ-V.bcmap) symlinked to file (78-RKSJ-V.bcmap) outside the package as that violates asar security integrity
  • async task error  error=Cannot cleanup: 

https://github.com/electron-userland/electron-builder/blob/f84a0831d1d02b782ad07d4f7feff79d96dd45ec/packages/app-builder-lib/src/asar/asarUtil.ts#L103-L111

It shouldn’t consider everything outside of appDir as problematic. For example, in the issue above, it’s copying a pdfjs folder from outside the appDir, and within pdfjs there are some symlink files that point to files within the pdfjs folder itself.

patch

diff --git a/packages/app-builder-lib/src/asar/asarUtil.ts b/packages/app-builder-lib/src/asar/asarUtil.ts
index 386dc993..4a2afc49 100644
--- a/packages/app-builder-lib/src/asar/asarUtil.ts
+++ b/packages/app-builder-lib/src/asar/asarUtil.ts
@@ -86,7 +86,7 @@ export class AsarPackager {
         return
       }
     }
-    const writeFileOrSymlink = async (transformedData: string | Buffer | undefined, source: string, destination: string, stat: fs.Stats) => {
+    const writeFileOrSymlink = async (transformedData: string | Buffer | undefined, source: string, destination: string, stat: fs.Stats,sourceDir:string) => {
       copiedFiles.add(destination)

       // If transformed data, skip symlink logic
@@ -100,9 +100,9 @@ export class AsarPackager {
         return this.copyFileOrData(undefined, source, destination, stat)
       }

-      const realPathRelative = path.relative(this.config.appDir, realPathFile)
-      const symlinkTarget = path.resolve(this.rootForAppFilesWithoutAsar, realPathRelative)
+      const realPathRelative = path.relative(sourceDir, realPathFile)
       const isOutsidePackage = realPathRelative.startsWith("..")
+      const symlinkTarget = path.resolve(this.rootForAppFilesWithoutAsar, realPathRelative)
       if (isOutsidePackage) {
         log.error({ source: log.filePath(source), realPathFile: log.filePath(realPathFile) }, `unable to copy, file is symlinked outside the package`)
         throw new Error(
@@ -130,7 +130,7 @@ export class AsarPackager {
         const dest = path.resolve(this.rootForAppFilesWithoutAsar, relative)

         matchUnpacker(file, dest, metadata)
-        taskManager.addTask(writeFileOrSymlink(transformedData, file, dest, metadata))
+        taskManager.addTask(writeFileOrSymlink(transformedData, file, dest, metadata, fileSet.src))

         if (taskManager.tasks.length >

same too…

We are still facing this issue on latest electron builder 26.0.11

Try cleaning node_modules and cache. Helped me.

I’ve debugged it a bit, and seems like it was resolving symlinked to workspace1/node_modules from workspace2/ into actual folder path, than failing on validating it, `cos those folders are outside of project.

That would be easy to test by replacing symlinked modules with real copy of workspace2 into workspace1/node_modules - didn’t test it though.

Anyway, update to 26.0.11, full clean, npm i solved the issue.

We are still facing this issue on latest electron builder 26.0.11

@rathboma I’ve tested v25.1.8, and it’s been fixed. You can update your electron-builder version. image

I can’t get it to happen in a small example. You can see the full project here: https://github.com/ulixee/platform/tree/main/desktop

The monorepo has a weird build process, which is probably why something is happening here that is out of the ordinary. We compile typescript into an entirely different directory and then builds node modules in that directory.

The desktop app is a submodule with a two app structure. So we have to actually copy over the project files so that the sub dependencies are found and packaged into the app.

I was trying out the new version because somehow only half of the native modules are added to asar unpacked. The latest version has the same problem - even though electron rebuilder shows them being rebuilt.