Skip to content

Node modules resolution in a Nx Monorepo #9445

@johnbwoodruff

Description

@johnbwoodruff

I have an electron app that is part of an Nx Monorepo. Since updating electron-builder on this project that has been working great for years I started seeing the following error when attempting to build:

• packaging       platform=darwin arch=universal electron=39.2.7 appOutDir=release/mac-universal
⨯ Detected file "Contents/Resources/app.asar.unpacked/node_modules/@nx/nx-darwin-arm64/nx.darwin-arm64.node" that's the same in both x64 and arm64 builds and not covered by the x64ArchFiles rule: "undefined"  failedTask=build stackTrace=Error: Detected file "Contents/Resources/app.asar.unpacked/node_modules/@nx/nx-darwin-arm64/nx.darwin-arm64.node" that's the same in both x64 and arm64 builds and not covered by the x64ArchFiles rule: "undefined"
    at makeUniversalApp (/Users/johnwoodruff/test/node_modules/@electron/universal/src/index.ts:181:17)
    at processTicksAndRejections (node:internal/process/task_queues:105:5)
    at MacPackager.doPack (/Users/johnwoodruff/test/node_modules/app-builder-lib/src/macPackager.ts:188:9)
    at MacPackager.pack (/Users/johnwoodruff/test/node_modules/app-builder-lib/src/macPackager.ts:252:9)
    at Packager.doBuild (/Users/johnwoodruff/test/node_modules/app-builder-lib/src/packager.ts:519:11)
    at executeFinally (/Users/johnwoodruff/test/node_modules/builder-util/src/promise.ts:12:14)
    at Packager.build (/Users/johnwoodruff/test/node_modules/app-builder-lib/src/packager.ts:439:31)
    at executeFinally (/Users/johnwoodruff/test/node_modules/builder-util/src/promise.ts:12:14)

Updating electron-builder was the only change I had made, there was no code or configuration changes made. I originally found #9399 and thought it was the same issue, but after chatting with @mmaietta on a couple attempts, the resolution for that issue did not help me. As a result I dug in deeper to see if my error had a different root cause. After walking through all the app-builder-lib code that handles this, I finally discovered this change: https://github.com/electron-userland/electron-builder/pull/9401/changes#diff-2acfffb0f522ae856a790f8c948ffa38d0f86f846bbd931495fa9643ab2b9c78R185 Specifically the appFileCopier.ts change. It changes the order of node_module search to look at projectDir first instead of appDir which it had been previously. While I am sure this was to fix something else, it ended up breaking for me in my usecase.

The reason why I need to search appDir first is due to how my Nx monorepo works. In this monorepo I have not only my electron app, but also other "apps" such as backend services, mobile apps, etc. So my root package.json and node_modules (the projectDir) include dependencies from all the various apps. So I do a two package.json structure as I need to define only my subset of dependencies that are important to the electron app. So once I've built my app into dist/apps/myapp and then move into the actual electron-builder portion that specifies that as the app directory. Prior to updating, it would use the correct node_modules in the appDir, and now it's pulling from the root directory which contains all those dependencies that should not be packaged.

Hopefully this provides enough info around my issue. I understand there's likely a reason for the change of the ordering of directories, so maybe a configuration that could allow specifying the preferred order as an override from the default behavior?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions