node.jsnpmsassnode-gypnode-sass

Problem installing npm install, unable to find python2, node-sass and node-gyp


I am starting a new Elixir project and trying to install npm in the assets folder. I keep running up against the same error, first python2 is not found, and then it is either an issue with node-sass or node-gyp.

Error Message:

npm error     variables, includes, depth, check, True)
npm error   File "/Users/username/Desktop/ProjectFolder/elixir-projects/project_name/assets/node_modules/node-gyp/gyp/pylib/gyp/input.py", line 399, in LoadTargetBuildFile
npm error     includes, True, check)
npm error   File "/Users/username/Desktop/ProjectFolder/elixir-projects/project_name/assets/node_modules/node-gyp/gyp/pylib/gyp/input.py", line 271, in LoadOneBuildFile
npm error     aux_data, includes, check)
npm error   File "/Users/username/Desktop/ProjectFolder/elixir-projects/project_name/assets/node_modules/node-gyp/gyp/pylib/gyp/input.py", line 308, in LoadBuildFileIncludesIntoDict
npm error     LoadOneBuildFile(include, data, aux_data, None, False, check),
npm error   File "/Users/username/Desktop/ProjectFolder/elixir-projects/project_name/assets/node_modules/node-gyp/gyp/pylib/gyp/input.py", line 251, in LoadOneBuildFile
npm error     None)
npm error   File "/Users/username/.node-gyp/18.18.2/include/node/common.gypi", line 1
npm error     e_data_file_flag%': 1
npm error                         ^
npm error SyntaxError: EOL while scanning string literal
npm error gyp ERR! configure error 
npm error gyp ERR! stack Error: `gyp` failed with exit code: 1
npm error gyp ERR! stack     at ChildProcess.onCpExit (/Users/username/Desktop/ProjectFolder/elixir-projects/project_name/assets/node_modules/node-gyp/lib/configure.js:345:16)
npm error gyp ERR! stack     at ChildProcess.emit (node:events:517:28)
npm error gyp ERR! stack     at ChildProcess._handle.onexit (node:internal/child_process:292:12)
npm error gyp ERR! System Darwin 23.4.0
npm error gyp ERR! command "/usr/local/bin/node" "/Users/username/Desktop/ProjectFolder/elixir-projects/project_name/assets/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
npm error gyp ERR! cwd /Users/username/Desktop/ProjectFolder/elixir-projects/project_name/assets/node_modules/node-sass
npm error gyp ERR! node -v v18.18.2
npm error gyp ERR! node-gyp -v v3.8.0
npm error gyp ERR! not ok 
npm error Build failed with error code: 1
npm error A complete log of this run can be found in: /Users/username/.npm/_logs/2024-06-04T16_41_15_604Z-debug-0.log

UPDATE: Answer added below


Solution

  • FIXED BY UPDATING ELIXIR

    I was using the wrong version of elixir but the solution below still works.

    The existing posts I have seen and their answers seem to be geared toward Windows users so I wanted to post the solution I found that works for MacOS users. Hopefully, this helps others.

    Ensure that python2 is installed on your system this might be redundant but you can find the python2 installer here

    export PYTHON=python2
    

    node-sass is deprecated, despite being used in the out-of-the-box node install command I found that uninstalling it and just using sass does the trick.

    npm uninstall node-sass
    npm install sass
    

    if node_modules exists in the folder

    rm -rf node_modules
    npm cache clean --force
    npm install 
    

    This worked for me after about 2 hours of trying to find the solution.