Skip to content

Error with node:alpine #508

Closed
Closed

Description

@Nqsty

Hello,

I'm trying to use the @sentry/sentry-webpack-plugin in a project with a Docker from node:alpine and my webpack build is giving the following errors:
Note: I launch the build with this: docker build --tag=api . --build-arg SENTRY_ORG=my-org --build-arg SENTRY_AUTH_TOKEN=my-auth-token

Step 17/21 : RUN yarn build
 ---> Running in 2b914c65edc5
yarn run v1.15.2
$ backpack build
(node:33) UnhandledPromiseRejectionWarning: Error: spawn Unknown system error -8
    at ChildProcess.spawn (internal/child_process.js:373:11)
    at spawn (child_process.js:559:9)
    at Object.execFile (child_process.js:224:15)
    at Promise (/usr/src/api/node_modules/@sentry/cli/js/helper.js:147:20)
    at new Promise (<anonymous>)
    at Object.execute (/usr/src/api/node_modules/@sentry/cli/js/helper.js:137:10)
    at Object.proposeVersion (/usr/src/api/node_modules/@sentry/cli/js/releases/index.js:57:8)
    at SentryCliPlugin.getReleasePromise (/usr/src/api/node_modules/@sentry/webpack-plugin/src/index.js:162:27)
    at new SentryCliPlugin (/usr/src/api/node_modules/@sentry/webpack-plugin/src/index.js:112:25)
    at Object.webpack (/usr/src/api/backpack.config.js:24:9)
(node:33) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:33) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:33) PromiseRejectionHandledWarning: Promise rejection was handled asynchronously (rejection id: 2)
(node:33) UnhandledPromiseRejectionWarning: Error: spawn Unknown system error -8
    at ChildProcess.spawn (internal/child_process.js:373:11)
    at spawn (child_process.js:559:9)
    at Object.execFile (child_process.js:224:15)
    at Promise (/usr/src/api/node_modules/@sentry/cli/js/helper.js:147:20)
    at new Promise (<anonymous>)
    at Object.execute (/usr/src/api/node_modules/@sentry/cli/js/helper.js:137:10)
    at Object.proposeVersion (/usr/src/api/node_modules/@sentry/cli/js/releases/index.js:57:8)
    at SentryCliPlugin.getReleasePromise (/usr/src/api/node_modules/@sentry/webpack-plugin/src/index.js:162:27)
    at new SentryCliPlugin (/usr/src/api/node_modules/@sentry/webpack-plugin/src/index.js:112:25)
    at Object.webpack (/usr/src/api/backpack.config.js:24:9)
(node:33) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 3)

Isolating the cli call, I have the following error on docker build:

Step 17/25 : RUN npx sentry-cli
 ---> Running in 3ee1764e848e
spawn Unknown system error -8
The command '/bin/sh -c npx sentry-cli' returned a non-zero code: 1

Isolating the package in node:alpine:

FROM node:alpine
RUN yarn add @sentry/webpack-plugin
RUN npx sentry-cli

Gives me the following output:

Step 1/3 : FROM node:alpine
 ---> 953c516e1466
Step 2/3 : RUN yarn add @sentry/webpack-plugin
 ---> Running in 476725a750e7
yarn add v1.15.2
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
success Saved 14 new dependencies.
info Direct dependencies
└─ @sentry/[email protected]
info All dependencies
├─ @sentry/[email protected]
├─ @sentry/[email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
└─ [email protected]
Done in 3.38s.
Removing intermediate container 476725a750e7
 ---> c7784ba53137
Step 3/3 : RUN npx sentry-cli
 ---> Running in 985421737f8a
internal/modules/cjs/loader.js:657
    throw err;
    ^

Error: Cannot find module '/root/.npm/_npx/1/lib/node_modules/sentry-cli/tasks/download.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:655:15)
    at Function.Module._load (internal/modules/cjs/loader.js:580:25)
    at Function.Module.runMain (internal/modules/cjs/loader.js:868:12)
    at internal/main/run_main_module.js:21:11
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] postinstall: `node tasks/download.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2019-04-08T21_47_01_099Z-debug.log
Install for sentry-cli@latest failed with code 1
The command '/bin/sh -c npx sentry-cli' returned a non-zero code: 1

I'm not sure what am I doing wrong right now. Are there some packages I should add to node:alpine so the cli works?

Thank you for your time.

Activity

  1. javiergarciagonzalez commented on Sep 26, 2019

    @javiergarciagonzalez

    Same here :(

  2. oprince commented on Nov 10, 2019

    @oprince

    Same here :(
    Any solution ?

  3. AvailCat commented on Nov 11, 2019

    @AvailCat

    It is not related with alpine, same issue on node:lts and node:lts-buster docker image, see #620

  4. tonyo commented on Nov 12, 2019

    @tonyo
    Contributor

    A few notes here:

    • The package is called @sentry/cli, not sentry-cli.
    • npx @sentry/cli should work under root after you do npm config set unsafe-perm true

    Feel free to provide another minimal failing example.

  5. kamilogorek commented on Mar 5, 2020

    @kamilogorek
    Contributor

    This should be resolved by now, see #620 (comment) + commit from Tonyo.

  6. lightninglu10 commented on Mar 10, 2020

    @lightninglu10

    @kamilogorek I'm still getting this error on "@sentry/cli": "^1.51.1".

    I tried on a node:slim image as well and am getting:

    /usr/src/app/node_modules/@sentry/cli/sentry-cli: 1: /usr/src/app/node_modules/@sentry/cli/sentry-cli: Syntax error: "(" unexpected
    

    Any idea what's up?

  7. kamilogorek commented on Mar 10, 2020

    @kamilogorek
    Contributor

    @lightninglu10 can you provide your Dockerfile?

  8. lightninglu10 commented on Mar 10, 2020

    @lightninglu10
    FROM node:alpine
    
    # install dependencies
    RUN apk add --no-cache --virtual .build-deps \
        git \
        python \
        make \
        g++
    
    # Create app directory
    RUN mkdir -p /usr/src/app
    WORKDIR /usr/src/app
    
    COPY package.json /usr/src/app
    COPY yarn.lock /usr/src/app
    COPY .sentryclirc /usr/src/app
    
    # install yarn and yarn install
    RUN yarn install --production --no-progress
    
    # Expose the public http port
    EXPOSE 3000
    
    # Bundle app source
    COPY . /usr/src/app
    ARG REACT_APP_ENV
    ENV REACT_APP_ENV=$REACT_APP_ENV
    ARG SENTRY_RELEASE
    RUN SENTRY_RELEASE=${SENTRY_RELEASE} REACT_APP_ENV=${REACT_APP_ENV} yarn run build
    RUN SENTRY_RELEASE=${SENTRY_RELEASE} yarn run sentry;
    
    # build and Start server
    CMD ["yarn", "start"]
    

    Where yarn run sentry runs a node.js file

    const SentryCli = require("@sentry/cli");
    
    async function createReleaseAndUpload() {
      const release = process.env.SENTRY_RELEASE;
      if (!release) {
        console.warn("SENTRY_RELEASE is not set");
    
        return;
      }
    
      const cli = new SentryCli();
    
      try {
        console.log("Creating sentry release " + release);
        await cli.releases.new(release);
    
        console.log("Uploading source maps");
        await cli.releases.uploadSourceMaps(release, {
          include: [".next/server/static/"],
          urlPrefix: "~/static/js",
          rewrite: false,
        });
    
        console.log("Finalizing release");
        await cli.releases.finalize(release);
      } catch (e) {
        console.error("Source maps uploading failed:", e);
      }
    }
    
    createReleaseAndUpload();
    
  9. kamilogorek commented on Mar 19, 2020

    @kamilogorek
    Contributor

    Unfortunately provided code isn't enough to reproduce the issue. I need a valid repro case for this to investigate.

  10. vitalyiegorov commented on Apr 3, 2020

    @vitalyiegorov

    The same problem as @lightninglu10 faced - working locally on OSX, but does not work in the docker container (tried node:10-alpine image also):

    FROM node:13.12.0-stretch
    ENV PATH="${PATH}:/root/.local/bin"
    RUN apt-get update && apt-get -f  --yes install curl python python-pip git \
        && (curl --compressed -o- -L https://yarnpkg.com/install.sh | bash) \
        && (curl --compressed -o- -L https://sentry.io/get-cli/ | bash) \
        && pip install awscli --upgrade --user
    

    Running sentry-cli from PATH works as expected, but running through NODE returns:
    /app/node_modules/@sentry/cli/sentry-cli: 1: /app/node_modules/@sentry/cli/sentry-cli: Syntax error: end of file unexpected (expecting ")")
    I guess there is something with node_modules/@sentry/cli/sentry-cli binary, @kamilogorek could you please help?

    Temporary fix to patch path to OS installed sentry-cli in the package.json:

    "postinstall": "sed -e \"s/return binaryPath;/return '/usr/local/bin/sentry-cli';/g\" -i.bak ./node_modules/@sentry/cli/js/helper.js"
    
  11. kmaid commented on Aug 6, 2021

    @kmaid

    I had this problem because i was using an yarn install from another (host) machine. I think the package compiles a binary which is system specific. Thats 4 hours of my life I will never get back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions