skip to Main Content

I’m building a NextJS 13 application. I’m usually working on Windows but out of my home I’m using a Mac. Everything is working correctly on Windows, but when I build the image on my Mac everything crashes (chip M1 by the way).

This is my dockerfile:

FROM node:16-alpine

WORKDIR /app

COPY package*.json .

RUN npm install

COPY . .

EXPOSE 3000

CMD npm run dev

This dockerfile crashes in the RUN npm install step just on Mac and throws a huge amount of errors

 => [internal] load build definition from .dockerfile-dev                    0.0s
 => => transferring dockerfile: 179B                                         0.0s
 => [internal] load .dockerignore                                            0.0s
 => => transferring context: 34B                                             0.0s
 => [internal] load metadata for docker.io/library/node:16-alpine            1.3s
 => [1/5] FROM docker.io/library/node:16-alpine@sha256:029a85552a270cd6dfae  0.0s
 => => resolve docker.io/library/node:16-alpine@sha256:029a85552a270cd6dfae  0.0s
 => [internal] load build context                                            0.1s
 => => transferring context: 1.69kB                                          0.0s
 => CACHED [2/5] WORKDIR /app                                                0.0s
 => [3/5] COPY package*.json .                                               0.0s
 => ERROR [4/5] RUN npm install                                             10.0s
------                                                                            
 > [4/5] RUN npm install:                                                         
#8 9.721 npm notice                                                               
#8 9.722 npm notice New major version of npm available! 8.19.3 -> 9.5.0           
#8 9.722 npm notice Changelog: <https://github.com/npm/cli/releases/tag/v9.5.0>   
#8 9.722 npm notice Run `npm install -g [email protected]` to update!                     
#8 9.722 npm notice 
#8 9.723 npm ERR! code 1
#8 9.724 npm ERR! path /app/node_modules/bufferutil
#8 9.725 npm ERR! command failed
#8 9.725 npm ERR! command sh -c -- node-gyp-build
#8 9.725 npm ERR! gyp info it worked if it ends with ok
#8 9.725 npm ERR! gyp info using [email protected]
#8 9.725 npm ERR! gyp info using [email protected] | linux | arm64
#8 9.725 npm ERR! gyp ERR! find Python 
#8 9.725 npm ERR! gyp ERR! find Python Python is not set from command line or npm configuration
#8 9.725 npm ERR! gyp ERR! find Python Python is not set from environment variable PYTHON
#8 9.725 npm ERR! gyp ERR! find Python checking if "python3" can be used
#8 9.725 npm ERR! gyp ERR! find Python - "python3" is not in PATH or produced an error
#8 9.725 npm ERR! gyp ERR! find Python checking if "python" can be used
#8 9.725 npm ERR! gyp ERR! find Python - "python" is not in PATH or produced an error
#8 9.725 npm ERR! gyp ERR! find Python 
#8 9.726 npm ERR! gyp ERR! find Python **********************************************************
#8 9.726 npm ERR! gyp ERR! find Python You need to install the latest version of Python.
#8 9.726 npm ERR! gyp ERR! find Python Node-gyp should be able to find and use Python. If not,
#8 9.726 npm ERR! gyp ERR! find Python you can try one of the following options:
#8 9.726 npm ERR! gyp ERR! find Python - Use the switch --python="/path/to/pythonexecutable"
#8 9.726 npm ERR! gyp ERR! find Python   (accepted by both node-gyp and npm)
#8 9.726 npm ERR! gyp ERR! find Python - Set the environment variable PYTHON
#8 9.726 npm ERR! gyp ERR! find Python - Set the npm configuration variable python:
#8 9.726 npm ERR! gyp ERR! find Python   npm config set python "/path/to/pythonexecutable"
#8 9.726 npm ERR! gyp ERR! find Python For more information consult the documentation at:
#8 9.726 npm ERR! gyp ERR! find Python https://github.com/nodejs/node-gyp#installation
#8 9.726 npm ERR! gyp ERR! find Python **********************************************************
#8 9.726 npm ERR! gyp ERR! find Python 
#8 9.726 npm ERR! gyp ERR! configure error 
#8 9.726 npm ERR! gyp ERR! stack Error: Could not find any Python installation to use
#8 9.726 npm ERR! gyp ERR! stack     at PythonFinder.fail (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/find-python.js:330:47)
#8 9.726 npm ERR! gyp ERR! stack     at PythonFinder.runChecks (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/find-python.js:159:21)
#8 9.727 npm ERR! gyp ERR! stack     at PythonFinder.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/find-python.js:202:16)
#8 9.727 npm ERR! gyp ERR! stack     at PythonFinder.execFileCallback (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/find-python.js:294:16)
#8 9.727 npm ERR! gyp ERR! stack     at exithandler (node:child_process:410:5)
#8 9.727 npm ERR! gyp ERR! stack     at ChildProcess.errorhandler (node:child_process:422:5)
#8 9.727 npm ERR! gyp ERR! stack     at ChildProcess.emit (node:events:513:28)
#8 9.727 npm ERR! gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:291:12)
#8 9.727 npm ERR! gyp ERR! stack     at onErrorNT (node:internal/child_process:485:16)
#8 9.727 npm ERR! gyp ERR! stack     at processTicksAndRejections (node:internal/process/task_queues:83:21)
#8 9.727 npm ERR! gyp ERR! System Linux 5.15.49-linuxkit
#8 9.727 npm ERR! gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
#8 9.727 npm ERR! gyp ERR! cwd /app/node_modules/bufferutil
#8 9.727 npm ERR! gyp ERR! node -v v16.19.1
#8 9.727 npm ERR! gyp ERR! node-gyp -v v9.1.0
#8 9.727 npm ERR! gyp ERR! not ok
#8 9.729 
#8 9.729 npm ERR! A complete log of this run can be found in:
#8 9.729 npm ERR!     /root/.npm/_logs/2023-02-22T02_35_48_229Z-debug-0.log
------
executor failed running [/bin/sh -c npm install]: exit code: 1

Would appreciate any insight in this, I have no idea why this is happening

2

Answers


  1. Chosen as BEST ANSWER

    I was able to solve this by simply stop ignoring the node_modules and removing some steps, but still have no idea why the container can't execute RUN npm install properly.

    Dockerfile now:

    FROM node:16-alpine
    
    WORKDIR /app
    
    COPY . .
    
    EXPOSE 3000
    
    CMD npm run dev
    

    Was able to access the page from the browser too. If anyone has any idea about the errors when executing the step RUN npm install or any way I can improve my Dockerfile, please post an answer.


  2. #8 9.725 npm ERR! gyp ERR! find Python - "python3" is not in PATH or produced an error
    #8 9.725 npm ERR! gyp ERR! find Python - "python" is not in PATH or produced an error
    #8 9.726 npm ERR! gyp ERR! find Python You need to install the latest version of Python.
    

    npm is complaining that it can’t find python installed on your mac.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search