Azure / static-web-apps-cli

Azure Static Web Apps CLI ✨
https://aka.ms/swa/cli-local-development
MIT License
600 stars 119 forks source link

Unable to install SWA CLI on Alpine Linux #509

Closed justinyoo closed 4 months ago

justinyoo commented 2 years ago

Describe the bug

I'm using a Docker container image, mcr.microsoft.com/azure-cli:2.33.1, which is based on Alpine Linux.

I installed nvm and the latest node v16.x successfully. But I wasn't able to install this SWA CLI. It threw an error:

~ # npm install -g @azure/static-web-apps-cli
npm notice
npm notice New minor version of npm available! 8.5.5 -> 8.10.0
npm notice Changelog: https://github.com/npm/cli/releases/tag/v8.10.0
npm notice Run npm install -g npm@8.10.0 to update!
npm notice
npm ERR! code ENOENT
npm ERR! syscall spawn sh
npm ERR! path /root/.nvm/versions/node/v16.15.0/lib/node_modules/@azure/static-web-apps-cli/node_modules/keytar
npm ERR! errno -2
npm ERR! enoent spawn sh ENOENT
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

To Reproduce Steps to reproduce the behavior:

  1. Open a container image like docker run -it mcr.microsoft.com/azure-cli:2.33.1
  2. Run the following commands:
# Update and upgrade
apk update && apk upgrade \
    && apk add -U curl bash ca-certificates openssl ncurses coreutils python2 make gcc g++ libgcc linux-headers grep util-linux binutils findutils \
    && apk add -U bash icu-libs krb5-libs libgcc libintl libssl1.1 libstdc++ zlib \
    && apk add -U libgdiplus --repository https://dl-3.alpinelinux.org/alpine/edge/testing/ \
    && apk add -U libc6-compat gcompat

# Install nvm
cd ~
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm

# Install node.js
nvm install --lts
nvm use --lts

# Install SWA CLI
npm install -g @azure/static-web-apps-cli
  1. See the error above

Expected behavior A clear and concise description of what you expected to happen.

The SWA CLI should be installed successfully.

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

Additional context Add any other context about the problem here.

If I ran the yarn command like:

corepack enable
yarn global add @azure/static-web-apps-cli

It was fine, but I still have the same issue after that, by running npm install or npm run build, etc...

manekinekko commented 2 years ago

Hey @justinyoo can you share the logs from npm install -g @azure/static-web-apps-cli --verbose please? It looks like an issue with Keytar, but I am not sure.

manekinekko commented 2 years ago

FYI, I opened an issue at https://github.com/atom/node-keytar/issues/461

justinyoo commented 2 years ago

Hey @justinyoo can you share the logs from npm install -g @azure/static-web-apps-cli --verbose please? It looks like an issue with Keytar, but I am not sure.

Sure. I also suspect the keytar side... Here's the log:

npm info run keytar@7.9.0 install node_modules/@azure/static-web-apps-cli/node_modules/keytar prebuild-install || npm run build
npm info run keytar@7.9.0 install { code: 'ENOENT', signal: undefined }
npm timing reify:rollback:createSparse Completed in 1502ms
npm timing reify:rollback:retireShallow Completed in 0ms
npm timing command:install Completed in 33815ms
npm notice
npm notice New minor version of npm available! 8.5.5 -> 8.11.0
npm notice Changelog: https://github.com/npm/cli/releases/tag/v8.11.0
npm notice Run npm install -g npm@8.11.0 to update!
npm notice
npm verb stack Error: spawn sh ENOENT
npm verb stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:283:19)
npm verb stack     at onErrorNT (node:internal/child_process:478:16)
npm verb stack     at processTicksAndRejections (node:internal/process/task_queues:83:21)
npm verb pkgid keytar@7.9.0
npm verb cwd /root
npm verb Linux 5.10.102.1-microsoft-standard-WSL2
npm verb argv "/root/.nvm/versions/node/v16.15.0/bin/node" "/root/.nvm/versions/node/v16.15.0/bin/npm" "install" "-g" "@azure/static-web-apps-cli" "--verbose"
npm verb node v16.15.0
npm verb npm  v8.5.5
npm ERR! code ENOENT
npm ERR! syscall spawn sh
npm ERR! path /root/.nvm/versions/node/v16.15.0/lib/node_modules/@azure/static-web-apps-cli/node_modules/keytar
npm ERR! errno -2
npm ERR! enoent spawn sh ENOENT
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm verb exit -2
npm timing npm Completed in 34015ms
npm verb unfinished npm timer reify 1653527205368
npm verb unfinished npm timer reify:build 1653527237627
npm verb unfinished npm timer build 1653527237628
npm verb unfinished npm timer build:deps 1653527237628
npm verb unfinished npm timer build:run:install 1653527237661
npm verb unfinished npm timer build:run:install:node_modules/@azure/static-web-apps-cli/node_modules/keytar 1653527237661
npm verb code -2
Nexyll commented 2 years ago

@justinyoo To fix the npm install of the asw CLI, I had to add the following packages: apk add --no-cache python3 py3-pip libsecret-dev alpine-sdk, then the npm install passed.

justinyoo commented 2 years ago

@justinyoo To fix the npm install of the asw CLI, I had to add the following packages: apk add --no-cache python3 py3-pip libsecret-dev alpine-sdk, then the npm install passed.

@Nexyll I installed what I had installed above + what you suggested, but still have the same error.

This time, I use the container image of mcr.microsoft.com/azure-cli:2.37.0 (version updated from 2.33.1 to 2.37.0).

tnabil commented 1 year ago

Hi, any updates on this issue or suggested workarounds?

reddyeshwar17 commented 1 year ago

hello team, I am also similar issue ..how to resolve it?

adrianhall commented 4 months ago

As of right now, I cannot reproduce,

/workspaces/alpine-tests # npm install -g @azure/static-web-apps-cli
npm warn deprecated inflight@1.0.6: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
npm warn deprecated glob@7.2.3: Glob versions prior to v9 are no longer supported
npm warn deprecated rimraf@3.0.2: Rimraf versions prior to v4 are no longer supported
npm warn deprecated rimraf@2.7.1: Rimraf versions prior to v4 are no longer supported

added 320 packages in 18s

48 packages are looking for funding
  run `npm fund` for details
npm notice
npm notice New minor version of npm available! 10.7.0 -> 10.8.1
npm notice Changelog: https://github.com/npm/cli/releases/tag/v10.8.1
npm notice To update run: npm install -g npm@10.8.1
npm notice

This is with image node:20-alpine3.19 - my Dev container looks like this:

{
    "name": "Alpine Dev",
    "image": "node:20-alpine3.19",
    "features": {
        "ghcr.io/devcontainers/features/common-utils:2": {}   
    }
}

This is with @azure/static-web-apps-cli:1.1.10 (latest version at time of writing)

I did try to build with mcr.microsoft.com/azure-cli:2.37.0, but that does not contain all the requirements for running node. (specifically, it does not contain the glibcxx libraries) and is based on an older (non-supported) version of Alpine Linux (3.15 - whereas the earliest Alpine Linux supported by Node is 3.19)

I'm not an expert on containerization, but my suggestion is to start with the requirements of your application (node, in this case) and go from there.