cancel
Showing results for 
Search instead for 
Did you mean: 

issue in building snap with node18.17.0 version

issue in building snap with node18.17.0 version

jawad
Long-established Member

I am building snap with node version 16.17.0 it works fine. but when I change the node version to 18.17.0 and build the snap app I got following issue. 

 

 

+ tar xzf - -C /home/boschrexroth/projects/mairotech/parts/mariotech/install/ --no-same-owner --strip-components=1
+ npm config set unsafe-perm true
npm ERR! `unsafe-perm` is not a valid npm option

npm ERR! A complete log of this run can be found in: /home/boschrexroth/.npm/_logs/2023-12-12T05_57_41_208Z-debug-0.log
Failed to build 'mariotech'.

Recommended resolution:
Check the build logs and ensure the part's configuration and sources are correct.



jawad_0-1702361629967.png

 

and this is my snapcraft.yaml file

name: mariotech
version: "1.0.0"
summary: mariotech project
description: |
  Programm is for showing web page of mariotech. Enter 'sudo snap logs ctrlx-node-hello-world.app -f | more' to see the output.
confinement: strict
#confinement: devmode
#icon: assets/icons/ICONHERE.png
grade: stable # must be 'stable' to release into candidate/stable channels
base: core20
type: app

apps:
  mariotech:
    command: bin/app
    daemon: simple
    # interfaces to connect to https://snapcraft.io/docs/supported-interfaces
    plugs:
      - network
      - network-bind
      - network-status
      - active-operation
      - datalayer
    slots:
      - package-assets
      - package-run
    restart-condition: always
    passthrough:
      restart-delay: 10s

parts:
  mariotech:
    plugin: npm
    source: .
    npm-node-version: "18.17.0"
  configs:
    plugin: dump
    source: ./configs
    organize:
      'package-assets/*': package-assets/${SNAPCRAFT_PROJECT_NAME}/

  www:
    plugin: dump
    source: ./www
    organize:
      '*': www/
     
slots:
  package-assets:
    interface: content
    content: package-assets
    source:
      read:
        - $SNAP/package-assets/${SNAPCRAFT_PROJECT_NAME}
  package-run:
    interface: content
    content: package-run
    source:
      write:
      - $SNAP_DATA/package-run/${SNAPCRAFT_PROJECT_NAME}

  plugs:
    active-solution:
      interface: content
      content: solutions
      target: $SNAP_COMMON/solutions
    datalayer:
      interface: content
      content: datalayer
      target: $SNAP_DATA/.datalayer
    build-environment:
      # Set the node version here. We recommend to use the latest LTS version.
      - NODE_VERSION: "18.17.0"

    # We don't use the npm plugin here, because it has no X-build capability (can't build arm64 target snaps on amd64).
 
    override-build: |
     
      # set target arch
      if [ $SNAPCRAFT_TARGET_ARCH == "arm64" ]; then
          arch="arm64"
      else
          arch="x64"
      fi    

      # fetch node
      echo fetching: $node_uri

      if [ ! -f "${SNAPCRAFT_PART_INSTALL}/bin/node" ]; then
          curl $node_uri | tar xzf - -C $SNAPCRAFT_PART_INSTALL/ --no-same-owner --strip-components=1
      fi
      # clean cache
      npm cache clean --force

      # install production dependencies
      npm install --production --ignore-scripts --no-fund --unsafe-perm

      # install nodemon as a development dependency
      npm install --save-dev nodemon

      # pack and install the app (only production)
      npm install -g --prefix $SNAPCRAFT_PART_INSTALL $(npm pack . | tail -1) --ignore-scripts --omit=dev --no-fund --unsafe-perm

      # remove unused node_modules
      rm -rf ${SNAPCRAFT_PART_INSTALL}/lib/node_modules/npm
      rm -rf ${SNAPCRAFT_PART_INSTALL}/lib/node_modules/corepack
                                   

 

11 REPLIES 11

CodeShepherd
Community Moderator
Community Moderator

There were incompatible changes in the used nodejs. We are using the latest version node 20. This was fixed in our SDK version 2.04.0. See code below:

override-build: |

      # detect target arch
      if [ $SNAPCRAFT_TARGET_ARCH == "arm64" ]; then
          target_arch="arm64"
      else 
          target_arch="x64"
      fi     

      # detect build arch
      if [ $SNAP_ARCH == "arm64" ]; then
          build_arch="arm64"
      else 
          build_arch="x64"
      fi     

      # fetch node for target arch to be packed
      if [ ! -f "${SNAPCRAFT_PART_INSTALL}/bin/node" ]; then
          node_path="${SNAPCRAFT_PART_INSTALL}/bin"
          node_uri=https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-${target_arch}.tar.gz
          echo fetching node for install: $node_uri
          curl $node_uri | tar xzf - -C $SNAPCRAFT_PART_INSTALL --no-same-owner --strip-components=1
      fi

      # fetch node used for build (if not equal to target arch for cross build)
      if [ $build_arch != $target_arch ]; then
        node_path=$SNAPCRAFT_PART_BUILD/bin
        if [ ! -f "${SNAPCRAFT_PART_BUILD}/bin/node" ]; then
          node_uri=https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-${build_arch}.tar.gz
          echo fetching node for build: $node_uri
          curl $node_uri | tar xzf - -C $SNAPCRAFT_PART_BUILD --no-same-owner --strip-components=1
        fi
      fi

      # set the path to build target node to be used for build
      echo node path: $node_path
      export PATH=$node_path:$PATH
      node --version
      npm --version

      # install and compile (tsc -> ./dist)
      npm install --ignore-scripts --no-fund --unsafe-perm
      npm run tsc

      # pack and install the app (only production)
      npm install -g --prefix $SNAPCRAFT_PART_INSTALL $(npm pack . | tail -1) --ignore-scripts --omit=dev --no-fund --unsafe-perm

      # remove ctrlx-datalayer prebuilds of unused archs to reduce snap size
      package_name=$(npm run getName -s)
      prebuilds_location="${SNAPCRAFT_PART_INSTALL}/lib/node_modules/${package_name}/node_modules/ctrlx-datalayer/prebuilds"
      if [ -d "$prebuilds_location" ]; then
        find $prebuilds_location -type f -not -ipath "*/linux-${target_arch}*" -delete
      fi

      # remove unused binaries
      rm -rf ${SNAPCRAFT_PART_INSTALL}/bin/npm
      rm -rf ${SNAPCRAFT_PART_INSTALL}/bin/npx
      rm -rf ${SNAPCRAFT_PART_INSTALL}/bin/corepack

      # remove unused node modules
      rm -rf ${SNAPCRAFT_PART_INSTALL}/lib/node_modules/npm
      rm -rf ${SNAPCRAFT_PART_INSTALL}/lib/node_modules/corepack

jawad
Long-established Member

I have changed the node version to 20.9.0 and got this issue while building snap app

Note: I am using js not ts

Building mariotech
+ snapcraftctl build
+ '[' '!' -f /home/boschrexroth/projects/mairotech/parts/mariotech/install/bin/node ']'
+ curl -s https://nodejs.org/dist/v20.9.0/node-v20.9.0-linux-x64.tar.gz
+ tar xzf - -C /home/boschrexroth/projects/mairotech/parts/mariotech/install/ --no-same-owner --strip-components=1

gzip: stdin: unexpected end of file
tar: Unexpected EOF in archive
tar: Unexpected EOF in archive
tar: Error is not recoverable: exiting now
Failed to build 'mariotech'.

Recommended resolution:
Check the build logs and ensure the part's configuration and sources are correct.

* The terminal process "/bin/bash '-c', 'bash build-snap-amd64.sh'" terminated with exit code: 2.

 

jawad
Long-established Member

I made above changes in my snapcraft.yaml file and got this issue now:

 

+ snapcraftctl build
+ cp --archive --link --no-dereference . /home/boschrexroth/projects/mairotech/parts/configs/install
Building mariotech
+ snapcraftctl build
+ '[' '!' -f /home/boschrexroth/projects/mairotech/parts/mariotech/install/bin/node ']'
+ curl -s https://nodejs.org/dist/v20.9.0/node-v20.9.0-linux-x64.tar.gz
+ tar xzf - -C /home/boschrexroth/projects/mairotech/parts/mariotech/install/ --no-same-owner --strip-components=1
+ npm config set unsafe-perm true
npm ERR! `unsafe-perm` is not a valid npm option

npm ERR! A complete log of this run can be found in: /home/boschrexroth/.npm/_logs/2023-12-12T10_08_13_242Z-debug-0.log
Failed to build 'mariotech'.

Recommended resolution:
Check the build logs and ensure the part's configuration and sources are correct.

* The terminal process "/bin/bash '-c', 'bash build-snap-amd64.sh'" terminated with exit code: 2.
* Terminal will be reused by tasks, press any key to close it.

jawad_0-1702375759835.png

 

CodeShepherd
Community Moderator
Community Moderator

In version Node 20 LTS the option "--unsafe-perm" is not longer available to you need to remove it from your snapcraft.yaml.

Or use the Node 18 LTS (sudo npm install node --channel=18/stable).

jawad
Long-established Member

I have upgraded  the node version to 20.9.0,but getting this error now. 
Note: I have removed unsafe-perm from snapcraft.yaml file

jawad_0-1702460691879.png

+ tar xzf - -C /home/boschrexroth/projects/mairotech/parts/mariotech/install/ --no-same-owner --strip-components=1
+ npm config set unsafe-perm true
npm ERR! `unsafe-perm` is not a valid npm option

npm ERR! A complete log of this run can be found in: /home/boschrexroth/.npm/_logs/2023-12-13T09_40_58_467Z-debug-0.log
Failed to build 'mariotech'.

Recommended resolution:
Check the build logs and ensure the part's configuration and sources are correct.

* The terminal process "/bin/bash '-c', 'bash build-snap-amd64.sh'" terminated with exit code: 2.
* Terminal will be reused by tasks, press any key to close it.

 

CodeShepherd
Community Moderator
Community Moderator

It seem the "unsafe-perm" option is still present in your snapcrat.yaml. Could you share it so we can have a look to it? Feel free to send it to me via private message if it should be visible in the forum.

jawad
Long-established Member

here is my snapcraft.yaml

 

name: mariotech
version: "1.0.0"
summary: mariotech project
description: |
  Programm is for showing web page of mariotech. Enter 'sudo snap logs ctrlx-node-hello-world.app -f | more' to see the output.
confinement: strict
#confinement: devmode
#icon: assets/icons/ICONHERE.png
grade: stable # must be 'stable' to release into candidate/stable channels
base: core20
type: app

apps:
  mariotech:
    command: bin/app
    daemon: simple
    # interfaces to connect to https://snapcraft.io/docs/supported-interfaces
    plugs:
      - network
      - network-bind
      - network-status
      - active-operation
      - datalayer
    slots:
      - package-assets
      - package-run
    restart-condition: always
    passthrough:
      restart-delay: 10s

parts:
  mariotech:
    plugin: npm
    source: .
    npm-node-version: "20.9.0"
  configs:
    plugin: dump
    source: ./configs
    organize:
      'package-assets/*': package-assets/${SNAPCRAFT_PROJECT_NAME}/

  www:
    plugin: dump
    source: ./www
    organize:
      '*': www/
     
slots:
  package-assets:
    interface: content
    content: package-assets
    source:
      read:
        - $SNAP/package-assets/${SNAPCRAFT_PROJECT_NAME}
  package-run:
    interface: content
    content: package-run
    source:
      write:
      - $SNAP_DATA/package-run/${SNAPCRAFT_PROJECT_NAME}

  plugs:
    active-solution:
      interface: content
      content: solutions
      target: $SNAP_COMMON/solutions
    datalayer:
      interface: content
      content: datalayer
      target: $SNAP_DATA/.datalayer
    build-environment:
      # Set the node version here. We recommend to use the latest LTS version.
      - NODE_VERSION: "20.9.0"

    # We don't use the npm plugin here, because it has no X-build capability (can't build arm64 target snaps on amd64).
 
    override-build: |
     
      # set target arch
      if [ $SNAPCRAFT_TARGET_ARCH == "arm64" ]; then
          arch="arm64"
      else
          arch="x64"
      fi    

      # fetch node
      echo fetching: $node_uri

      if [ ! -f "${SNAPCRAFT_PART_INSTALL}/bin/node" ]; then
          curl $node_uri | tar xzf - -C $SNAPCRAFT_PART_INSTALL/ --no-same-owner --strip-components=1
      fi
      # clean cache
      npm cache clean --force

      # install production dependencies
      npm install --production --ignore-scripts --no-fund

      # install nodemon as a development dependency
      npm install --save-dev nodemon

      # pack and install the app (only production)
      npm install -g --prefix $SNAPCRAFT_PART_INSTALL $(npm pack . | tail -1) --ignore-scripts --omit=dev --no-fund

      # remove unused node_modules
      rm -rf ${SNAPCRAFT_PART_INSTALL}/lib/node_modules/npm
      rm -rf ${SNAPCRAFT_PART_INSTALL}/lib/node_modules/corepack

nickH
Community Moderator
Community Moderator

Hi @jawad 

We are currently working on a solution for this issue and will publish a patch for the SDK including a bugfix in the new year. 

Best regards and happy holidays! 

jawad
Long-established Member

OK
Thanks @nickH 
i will be waiting

nickH
Community Moderator
Community Moderator

Hi @jawad 

sorry for coming back so late. With the V2.6 SDK this issue seems to be fixed. Can you try out as well? 

I just tried with the sample: samples-node/datalayer.provider.alldata from the SDK and was able to build the snap successfully. But be carefull the build can take some time. 

Best regards, 

Nick

CodeShepherd
Community Moderator
Community Moderator

@jawad Are there any news? Could this issue been solved.

Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist