forge icon indicating copy to clipboard operation
forge copied to clipboard

With no changes, "Cannot find module 'appdmg'"

Open busterbogheart opened this issue 2 years ago • 16 comments

Pre-flight checklist

  • [X] I have read the contribution documentation for this project.
  • [X] I agree to follow the code of conduct that this project uses.
  • [X] I have searched the issue tracker for a bug that matches the one I want to file, without success.

Electron Forge version

6.4.1

Electron version

v24.8.1

Operating system

macOS 11.3.1

Last known working Electron Forge version

6.1.1

Expected behavior

Our build is running in Circle CI, and without changes recently this issue happens. We've tried pegging the @electron-forge modules to 6.1.1, but the issue remains.

Any recent changes in forge that could cause the Cannot find module 'appdmg' error?

Actual behavior

 electron-forge:hook hook triggered: postPackage +20s
[SUCCESS] Running postPackage hook
[SUCCESS] Running package command
[STARTED] Running preMake hook
  electron-forge:hook hook triggered: preMake +1ms
[SUCCESS] Running preMake hook
[STARTED] Making distributables
  electron-forge:hook hook triggered: readPackageJson +1ms
[STARTED] Making a dmg distributable for darwin/x64
[FAILED] Cannot find module 'appdmg'
[FAILED] Require stack:
[FAILED] - /Users/distiller/repo/node_modules/electron-installer-dmg/src/index.js
[FAILED] - /Users/distiller/repo/node_modules/@electron-forge/maker-dmg/dist/MakerDMG.js
[FAILED] - /Users/distiller/repo/node_modules/@electron-forge/core/dist/util/require-search.js
[FAILED] - /Users/distiller/repo/node_modules/@electron-forge/core/dist/util/plugin-interface.js
[FAILED] - /Users/distiller/repo/node_modules/@electron-forge/core/dist/util/forge-config.js
[FAILED] - /Users/distiller/repo/node_modules/@electron-forge/core/dist/util/index.js
[FAILED] - /Users/distiller/repo/node_modules/@electron-forge/core/dist/api/index.js
[FAILED] - /Users/distiller/repo/node_modules/@electron-forge/cli/dist/electron-forge-publish.js

### Steps to reproduce

Unknown

### Additional information

_No response_

busterbogheart avatar Oct 04 '23 17:10 busterbogheart

Looks like the appdmg package is not installed for some reason. If you cache your node_modules on CircleCI, you could try nuking the cache so the dependencies are reinstalled (that would also give you a log with some useful info if something goes wrong).

erikian avatar Oct 20 '23 00:10 erikian

Hello, I have the same issue and would like to add some insight I gained while losing my sanity while investigating this issue.

I encountered this issue while working on chainner. I noticed that this Github actions workflow suddenly started failing on macOS when I changed a file totally unrelated to the workflow. I got the same error message as @busterbogheart:

[FAILED] Cannot find module 'appdmg'
[FAILED] Require stack:
[FAILED] - /Users/runner/work/chaiNNer/chaiNNer/node_modules/electron-installer-dmg/src/index.js
[FAILED] - /Users/runner/work/chaiNNer/chaiNNer/node_modules/@electron-forge/maker-dmg/dist/MakerDMG.js
...

While investigating this issue, I found 2 main things:

Firstly, the issue is definitely related to caches. Removing the cache: 'npm' from the workflow consistently triggered the issue.

Secondly, I noticed the logs of all successful and failed builds were identical until the Cannot find module 'appdmg' except for one detail: native dependencies. Here's the diff of 2 logs (one successful one not):

 [SUCCESS] Running prePackage hook from forgeConfig
 [STARTED] [plugin-webpack] Preparing native dependencies
 [TITLE] [plugin-webpack] Preparing native dependencies
-[TITLE] [plugin-webpack] Preparing native dependencies: 0 / 1
-[TITLE] [plugin-webpack] Preparing native dependencies: 1 / 1
-[SUCCESS] [plugin-webpack] Preparing native dependencies: 1 / 1
+[SUCCESS] [plugin-webpack] Preparing native dependencies
 [STARTED] [plugin-webpack] Building webpack bundles
 [SUCCESS] [plugin-webpack] Building webpack bundles
 [SUCCESS] Running prePackage hook
@@ -68,6 +66,55 @@
 [SUCCESS] Running preMake hook
 [STARTED] Making distributables
 [STARTED] Making a dmg distributable for darwin/universal
-[SUCCESS] Making a dmg distributable for darwin/universal
+[FAILED] Cannot find module 'appdmg'
+[FAILED] Require stack:
+[FAILED] - /Users/runner/work/chaiNNer/chaiNNer/node_modules/electron-installer-dmg/src/index.js
+[FAILED] - /Users/runner/work/chaiNNer/chaiNNer/node_modules/@electron-forge/maker-dmg/dist/MakerDMG.js
+...

As we can see, the successful runs always prepare one native dependency, while the failed runs do not. This native dependency is specific to macOS (my windows and linux runs never have it), so I suspect that appdmg is the native dependency.

RunDevelopment avatar Nov 03 '23 16:11 RunDevelopment

I'm having this issue randomly also with GitHub actions. 1 hour to develop a new feature, 6+ hours trying to fix an npm issue :)

The issue seems to be with npm install/npm ci (at least in my case), as arborist/reify (used by @electron/rebuild says not to care about appdmg sometimes:

npm verb reify failed optional dependency /Users/runner/work/focusanchor/focusanchor/node_modules/appdmg
npm sill reify mark deleted [
npm sill reify   '/Users/runner/work/focusanchor/focusanchor/node_modules/appdmg',
npm sill reify   '/Users/runner/work/focusanchor/focusanchor/node_modules/.bin/appdmg'
npm sill reify ]

I can't figure out why it's not including appdmg.


I've tried updating forge.config to not use the cache, and to use appdmg as a forced module to rebuild:

  rebuildConfig: {
    force: true,
    useCache: true,
    extraModules: ['appdmg']
  },

I've added appdmg as a devdependency directly. I've updated electron-forge and all libraries to the latest versions.

I've updated GitHub actions to check if it's now returning different OS platform details so the appdmg 'os' setting wouldn't match, but that's all fine

    - name: Dump runner OS
      run: echo "${{ runner.os }}"
    - name: Dump NPM OS Platform
      run: node -e "console.log(os.platform());"

I've changed it to rm -rf node_modules before npm installing, just in case!

Nothing helps/works 😭

ashleyhindle avatar Nov 04 '23 17:11 ashleyhindle

After removing Windows from my matrix the OSX build succeeds consistently 🤔

ashleyhindle avatar Nov 04 '23 18:11 ashleyhindle

@ashleyhindle if you're cachingnode_modules in any way the cache key needs to include platform, otherwise it sounds like you're restoring a cached set of windows node_modules onto your macos runner which won't have appdmg set up because that module is only installed on macos hosts

MarshallOfSound avatar Nov 04 '23 18:11 MarshallOfSound

@ashleyhindle if you're cachingnode_modules in any way the cache key needs to include platform, otherwise it sounds like you're restoring a cached set of windows node_modules onto your macos runner which won't have appdmg set up because that module is only installed on macos hosts

Unfortunately I don't cache node_modules. Unfortunately nothing in my setup changed between my successful publish 2~ months ago, and my failed attempt today.

ashleyhindle avatar Nov 04 '23 18:11 ashleyhindle

This is happening in my GitHub actions as well, Ive found that it correlates to the version of the Github runner.

macos-12: 20231029.1 causes a failure macos-12: 20230921.1 produces a valid build

davidjmeyer avatar Nov 08 '23 09:11 davidjmeyer

This issue happened to me today.

~Solution was~

npm i appdmg --save-optional

~use --save-optional if you are building for different platforms.~

Edit: It started failing again on the next build.

bboure avatar Nov 13 '23 17:11 bboure

I am having this issue as well, not sure if I have anything meaningful to contribute as far as data points go.

ghost avatar Nov 21 '23 20:11 ghost

Hope the above helps those using github workflows. It seems to be caused by python.

1000TurquoisePogs avatar Nov 27 '23 18:11 1000TurquoisePogs

@1000TurquoisePogs I end up with another issue after I've configured CI to install setuptools before npm ci and npm run make steps:

[STARTED] Making a dmg distributable for darwin/x64
[STARTED] Making a dmg distributable for darwin/arm64
[FAILED] Target already exists
[FAILED] Target already exists

An unhandled rejection has occurred inside Forge:
Error: Target already exists
at /Users/{user}/{projectPath}/{projectName}/node_modules/appdmg/lib/appdmg.js:80:53
    at node:fs:2313:7
    at FSReqCallback.oncomplete (node:fs:191:23)

I'm pretty sure this relates to https://github.com/LinusU/node-appdmg/issues/130, although it is not an upstream error. It seems Forge should be the one taking care of cleanup and it's a problem in Forge it picks the path where it isn't possible to write to a file (since another file already exists there). Moreover, the overwrite flag that is announced in the upstream issue and PR seems to be an optional in the future and possibly set to false by default, which means an action from Forge maintainers might be necessary sooner or later.

Also, it is still failing for me on CI re-runs with older source code and lockfile (with both appdmg module issue and Target already exists ones), which makes this issue even more surprising and could mean a breakage either with the deps or in CI image I've been using.

SpacingBat3 avatar Nov 30 '23 20:11 SpacingBat3

Had the same issue on Mac. After hrs of tinkering, I tried to install the package manually via npm i -D appdmg and it failed, complaining about my python version 3.12. So, I changed my global python version to 3.11.4 via

pyenv global 3.11.4

And its working fine now. Hope this helps anyone else.

hopkins385 avatar Feb 05 '24 21:02 hopkins385

Here is the fix if you want to keep 3.12 (github action default python versions) https://github.com/LinusU/node-appdmg/issues/234

jgresham avatar Apr 08 '24 22:04 jgresham

It looks like GHA mac runner has installed brew and python in some new way which is now giving an error. The --break-system-packages flag fixes the error for me (I don't use python for other things in my actions) so my command is now: python3 -m pip install setuptools --break-system-packages

New error:

Run python3 -m pip install setuptools
  python3 -m pip install setuptools
  shell: /bin/bash -e {0}
error: externally-managed-environment

× This environment is externally managed
╰─> To install Python packages system-wide, try brew install
    xyz, where xyz is the package you are trying to
    install.
    
    If you wish to install a Python library that isn't in Homebrew,
    use a virtual environment:
    
    python[3](https://github.com/NiceNode/nice-node/actions/runs/8803883604/job/24163039602#step:2:3) -m venv path/to/venv
    source path/to/venv/bin/activate
    python3 -m pip install xyz
    
    If you wish to install a Python application that isn't in Homebrew,
    it may be easiest to use 'pipx install xyz', which will manage a
    virtual environment for you. You can install pipx with
    
    brew install pipx
    
    You may restore the old behavior of pip by passing
    the '--break-system-packages' flag to pip, or by adding
    'break-system-packages = true' to your pip.conf file. The latter
    will permanently disable this error.
    
    If you disable this error, we STRONGLY recommend that you additionally
    pass the '--user' flag to pip, or set 'user = true' in your pip.conf
    file. Failure to do this can result in a broken Homebrew installation.
    
    Read more about this behavior here: <https://peps.python.org/pep-0[6](https://github.com/NiceNode/nice-node/actions/runs/8803883604/job/24163039602#step:2:7)68/>

note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
hint: See PEP 66[8](https://github.com/NiceNode/nice-node/actions/runs/...) for the detailed specification.
Error: Process completed with exit code 1.

jgresham avatar Apr 23 '24 17:04 jgresham

macos-12: 20230921.1

Thanks! It works for me:

    - name: Install Python 3.11.4
      uses: actions/setup-python@v4
      with:
        python-version: '3.11.4'

RexWzh avatar May 10 '24 19:05 RexWzh

If using GitHub Actions with the macos-latest image, it is also possible to install the setuptools via brew to avoid downgrading the Python version:

      - name: Set up Python for appdmg to be installed
        run: brew install python-setuptools

eliandoran avatar Aug 10 '24 11:08 eliandoran

Got this locally after upgrading Python via Homebrew. The fix for me was:

  1. brew upgrade python-setuptools
  2. rm -rf node_modules
  3. npm install

Then the build worked.

nikwen avatar Oct 30 '24 00:10 nikwen

Any updates on that matter? I have two runners, macos-latest and macOS-13, both updated to LTS Node (22), but it's not working anymore. This solution was previously effective for me with Node 20:

macos-12: 20230921.1

Thanks! It works for me:

- name: Install Python 3.11.4
  uses: actions/setup-python@v4
  with:
    python-version: '3.11.4'

BinarySoftware avatar Nov 17 '24 22:11 BinarySoftware

I had the same error but got it working by updating the ownership for the npm cache in my home directory:

sudo chown username:staff -R ~/.npm/_cacache

nikobojs avatar Jan 24 '25 09:01 nikobojs

Hey all, this should be fixed in a newer version of @electron/rebuild where we've forked our older version of node-gyp to support rebuilding without setuptools. See https://github.com/electron/rebuild/pull/1157 for more info.

As long as your lockfile is pointing at @electron/rebuild@^3.7.0 (required on newer versions of Forge), this should work as intended.

The workarounds of installing setuptools or just downgrading Python versions should work as well.

Unfortunately the error was very transparent because appdmg is listed in optionalDependencies (being macOS-only).

erickzhao avatar Jan 31 '25 05:01 erickzhao