Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getaddrinfo EAI_AGAIN github.com in electron@11.0.3~postinstall #173

Closed
cognition9144 opened this issue Dec 9, 2020 · 18 comments
Closed

Comments

@cognition9144
Copy link

I generated a generated-sources.json for https://github.com/yang991178/fluent-reader, and wrote the build yaml as per the sample. But when it runs 'npm install --offline --prefix=fluent-reader --verbose --cache=$FLATPAK_BUILDER_BUILDDIR/flatpak-node/npm-cache', it raises an error:

npm info lifecycle electron@11.0.3~postinstall: electron@11.0.3

> electron@11.0.3 postinstall /run/build/fluent-reader/fluent-reader/node_modules/electron
> node install.js

RequestError: getaddrinfo EAI_AGAIN github.com
    at ClientRequest.<anonymous> (/run/build/fluent-reader/fluent-reader/node_modules/got/source/request-as-event-emitter.js:178:14)
    at Object.onceWrapper (events.js:422:26)
    at ClientRequest.emit (events.js:327:22)
    at ClientRequest.origin.emit (/run/build/fluent-reader/fluent-reader/node_modules/@szmarczak/http-timer/source/index.js:37:11)
    at TLSSocket.socketErrorListener (_http_client.js:469:9)
    at TLSSocket.emit (events.js:315:20)
    at emitErrorNT (internal/streams/destroy.js:106:8)
    at emitErrorCloseNT (internal/streams/destroy.js:74:3)
    at processTicksAndRejections (internal/process/task_queues.js:80:21)
npm verb lifecycle electron@11.0.3~postinstall: unsafe-perm in lifecycle true

The build yaml file:

app-id: me.hyliu.fluentreader
runtime: org.freedesktop.Platform
runtime-version: "20.08"
branch: stable
sdk: org.freedesktop.Sdk
base: org.electronjs.Electron2.BaseApp
base-version: 20.08
sdk-extensions:
  - org.freedesktop.Sdk.Extension.node14
command: fluent-reader
separate-locales: false
finish-args:
  - --share=ipc
  - --socket=x11
  - --socket=pulseaudio
  - --share=network
modules:
  # First step is to install Node to /app/node, that way it can be accessible outside of the sdk
  # environment. install-sdk.sh is used because install.sh omits npm.
  # (This does not need to be done for electron-builder, see
  # electron-webpack-quick-start's build.electron.webpack.ElectronWebpackQuickStart.yaml for an
  # explanation.)
  # - name: node
  #   buildsystem: simple
  #   build-commands:
  #     - '/usr/lib/sdk/node14/install-sdk.sh'

  # Now is the quickstart module.
  - name: fluent-reader
    buildsystem: simple
    build-options:
      # Add the node bin directory.
      append-path: /usr/lib/sdk/node14/bin
      env:
        # Set the Electron cache directory.
        # (The directory format is: /run/build/MODULE_NAME/flatpak-node/electron-cache)
        ELECTRON_CACHE: '/run/build/fluent-reader/flatpak-node/electron-cache'
        # Sets the directory where Node is located so way npm won't download the headers.
        npm_config_nodedir: '/usr/lib/sdk/node14'
    build-commands:
      # Have Yarn use the offline mirror.
      - 'npm install --offline --prefix=fluent-reader --verbose --cache=$FLATPAK_BUILDER_BUILDDIR/flatpak-node/npm-cache'
      # Download the packages.
      # If you were using npm with electron-webpack/electron-builder, then the above two commands
      # would look more like the npm commands in the vanilla-quick-start manifest, just without
      # the --prefix.

      # Run electron-builder, passing the architecture arguments to it.
      # Note that the -- is important; without that, the argument will be passed to
      # yarn instead of electron-builder.
      - ". flatpak-node/electron-builder-arch-args.sh; npm run --prefix=fluent-reader --offline package-linux -- $ELECTRON_BUILDER_ARCH_ARGS"
      # Copy the resulting, unpacked directory to /app.
      # (A glob is used because the directory name may contain the current arch.)
      - "cp -r bin/linux*unpacked /app/fluent-reader"
      # If you passed --electron-non-patented-ffmpeg, you could install it like this:
      # - 'install -Dm 755 flatpak-node/libffmpeg.so -t /app/electron-webpack-quick-start'
      # Install the wrapper script to start it.
      - "install -Dm 755 start-fluent-reader.sh /app/bin/start-fluent-reader"
    sources:
      - type: git
        url: https://github.com/yang991178/fluent-reader
        # Use the Electron 4 / Node 10 version.
        commit: master
        # Checkout into a subdirectory so we can copy the whole thing to /app.
        dest: fluent-reader
      # Add the flatpak-node-generator generated sources.
      - generated-sources.json
      # Our runner script.
      - type: script
        dest-filename: start-fluent-reader.sh
        commands:
          - 'export PATH=$PATH:/app/node/bin'
          - 'npm start --prefix=/app/fluent-reader'
@gasinvein
Copy link
Member

gasinvein commented Dec 9, 2020

Since it's a modern electron which probably uses electron/get module, try using --xdg-layout option for flatpak-node-generator. You'll also need to remove npm_config_nodedir and replace ELECTRON_CACHE with XDG_CACHE_HOME: /run/build/fluent-reader/flatpak-node/cache.

@cognition9144
Copy link
Author

That worked! Thanks!

@refi64
Copy link
Collaborator

refi64 commented Dec 11, 2020 via email

@gasinvein
Copy link
Member

@refi64 Looks like it. But it would be a breaking change for existing apps with older electron. Maybe print a warning when modern electron is detected, but xdg-layout not enabled?

@proletarius101
Copy link
Contributor

proletarius101 commented Jan 30, 2021

Since it's a modern electron which probably uses electron/get module, try using --xdg-layout option for flatpak-node-generator. You'll also need to remove npm_config_nodedir and replace ELECTRON_CACHE with XDG_CACHE_HOME: /run/build/fluent-reader/flatpak-node/cache.

@gasinvein
How about yarn? I got exactly the same error for https://github.com/flathub/flathub/pull/2086/files, with

 python flatpak-node-generator.py yarn yarn.lock -o generated-sources.json --xdg-layout -r --electron-node-headers

@gasinvein
Copy link
Member

@proletarius101 I think npm/yarn doesn't make difference here, the error as @xcffl reported originates from a postinstall script, not from the package manager.

@gasinvein
Copy link
Member

@proletarius101 Your error in flathub/flathub#2086 comes from node-gyp trying to download node headers for electron (note version v9.4.2). Try adding --electron-node-headers option to the generator args.

@proletarius101
Copy link
Contributor

@proletarius101 Your error in flathub/flathub#2086 comes from node-gyp trying to download node headers for electron (note version v9.4.2). Try adding --electron-node-headers option to the generator args.

Well I did it, as shown above.
Locally I've removed the electron post-install job, which leads to the node-gyp error, and then the problem of this issue shows.

@gasinvein
Copy link
Member

Can you please point me to the exact errors you're getting?
I can see only this one in flathub builder log

error /run/build/standardnotes/app/node_modules/keytar: Command failed.
Exit code: 1
Command: prebuild-install || node-gyp rebuild
Arguments: 
Directory: /run/build/standardnotes/app/node_modules/keytar
Output:
prebuild-install WARN install getaddrinfo EAI_AGAIN github.com
gyp info it worked if it ends with ok
gyp info using node-gyp@5.1.0
gyp info using node@14.15.4 | linux | x64
gyp info find Python using Python version 3.8.7 found at "/usr/bin/python"
gyp http GET https://electronjs.org/headers/v9.4.2/node-v9.4.2-headers.tar.gz
gyp WARN install got an error, rolling back install
gyp ERR! configure error 
gyp ERR! stack Error: getaddrinfo EAI_AGAIN electronjs.org
gyp ERR! stack     at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:67:26)
gyp ERR! System Linux 5.4.0-62-generic
gyp ERR! command "/usr/lib/sdk/node14/bin/node" "/usr/lib/sdk/node14/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /run/build/standardnotes/app/node_modules/keytar
gyp ERR! node -v v14.15.4
gyp ERR! node-gyp -v v5.1.0
gyp ERR! not ok

It comes from node-gyp unable to find node headers, and it's a different one from what was reported in this issue.

@proletarius101
Copy link
Contributor

Can you please point me to the exact errors you're getting?
I can see only this one in flathub builder log

error /run/build/standardnotes/app/node_modules/keytar: Command failed.
Exit code: 1
Command: prebuild-install || node-gyp rebuild
Arguments: 
Directory: /run/build/standardnotes/app/node_modules/keytar
Output:
prebuild-install WARN install getaddrinfo EAI_AGAIN github.com
gyp info it worked if it ends with ok
gyp info using node-gyp@5.1.0
gyp info using node@14.15.4 | linux | x64
gyp info find Python using Python version 3.8.7 found at "/usr/bin/python"
gyp http GET https://electronjs.org/headers/v9.4.2/node-v9.4.2-headers.tar.gz
gyp WARN install got an error, rolling back install
gyp ERR! configure error 
gyp ERR! stack Error: getaddrinfo EAI_AGAIN electronjs.org
gyp ERR! stack     at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:67:26)
gyp ERR! System Linux 5.4.0-62-generic
gyp ERR! command "/usr/lib/sdk/node14/bin/node" "/usr/lib/sdk/node14/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /run/build/standardnotes/app/node_modules/keytar
gyp ERR! node -v v14.15.4
gyp ERR! node-gyp -v v5.1.0
gyp ERR! not ok

It comes from node-gyp unable to find node headers, and it's a different one from what was reported in this issue.

Yes. I faced two issues... keytar is the first one. Another is what was reported in this issue. I can't bypass both, although the keytar one (as shown in the build server log) could be bypassed locally by removing this step.

@gasinvein
Copy link
Member

You shouldn't remove this step, otherwise keytar likely won't work (node abi versions must match for native modules). Better figure out why node-gyp doesn't pick up cached headers.

@proletarius101
Copy link
Contributor

You shouldn't remove this step, otherwise keytar likely won't work (node abi versions must match for native modules). Better figure out why node-gyp doesn't pick up cached headers.

Obviously all three generated-sources.json contain no header v5.0.10, but only `v9.4.2". No idea why...

@gasinvein
Copy link
Member

gasinvein commented Jan 30, 2021

5.1.0 is the version of node-gyp itself. It tries to find electron node-headers version 9.4.2:

gyp http GET https://electronjs.org/headers/v9.4.2/node-v9.4.2-headers.tar.gz

@proletarius101
Copy link
Contributor

5.1.0 is the version of node-gyp itself. It tries to find electron node-headers version 9.4.2:

That's right. But "url": "https://www.electronjs.org/headers/v9.4.2/node-v9.4.2-headers.tar.gz", is in generated-sources.json already? https://github.com/flathub/flathub/blob/cda8a882ea1f10339bd91742cc333185798164fc/generated-sources.json

@proletarius101
Copy link
Contributor

Oh, I see. It's "dest": "flatpak-node/cache/node-gyp/9.4.2" rather than "dest": "flatpak-node/yarn-mirror". But that means it doesn't respect XDG_CACHE_HOME: /run/build/standardnotes/flatpak-node/cache?

@gasinvein
Copy link
Member

Dest flatpak-node/cache/node-gyp/9.4.2 is correct, the node headers tarball is not a npm/yarn packages, so it shouldn't be in the yarn offline mirror. Though if it doesn't respect XDG_CACHE_HOME, it should fall back to ~/.node-gyp. Maybe try creating symlink ~/.node-gyp -> ~/$XDG_CACHE_HOME/node-gyp prior to running the build command (in the same shell, as part of the same flatpak-builder command)?

@proletarius101
Copy link
Contributor

Well, that didn't work. But I found a solution: npm_config_nodedir: /run/build/standardnotes/flatpak-node/cache/node-gyp/9.4.2

@proletarius101
Copy link
Contributor

proletarius101 commented Feb 1, 2021

Just to add another note here, in case someone meet the same problem. If you see electron-builder triggers

npm info it worked if it ends with ok
npm verb cli [
npm verb cli   '/usr/lib/sdk/node14/bin/node',
npm verb cli   '/usr/lib/sdk/node14/bin/npm',
npm verb cli   'install',
npm verb cli   '--production',
npm verb cli   '--cache-min',
npm verb cli   '999999999'
npm verb cli ]

which requires internet access, the cause is some of your package.json don't have a package-lock.json along with. Particularly, if you use webpack (not electron-webpack), it may generate intermediate files under build/ without a package-lock.json. You need to copy the lockfile there, probably from app/ or src/.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants