【问题标题】:running npm install gives me these errors运行 npm install 给了我这些错误
【发布时间】:2021-08-10 12:08:48
【问题描述】:

I have tried a lot of things in order to fix this but can t find a solution, installed node sass that just added more problems, it used to run without a problem now I keep getting errors

npm ERR! code 1
    npm ERR! path D:\sb-app\node_modules\node-sass
    npm ERR! command failed
    npm ERR! command C:\Windows\system32\cmd.exe /d /s /c node scripts/build.js
    npm ERR! Building: C:\Program Files\nodejs\node.exe D:\sb-app\node_modules\node-gyp\bin\node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
    npm ERR! gyp info it worked if it ends with ok
    npm ERR! gyp verb cli [
    npm ERR! gyp verb cli   'C:\\Program Files\\nodejs\\node.exe',
    npm ERR! gyp verb cli   'D:\\sb-app\\node_modules\\node-gyp\\bin\\node-gyp.js',
    npm ERR! gyp verb cli   'rebuild',
    npm ERR! gyp verb cli   '--verbose',
    npm ERR! gyp verb cli   '--libsass_ext=',
    npm ERR! gyp verb cli   '--libsass_cflags=',
    npm ERR! gyp verb cli   '--libsass_ldflags=',
    npm ERR! gyp verb cli   '--libsass_library='
    npm ERR! gyp verb cli ]
    npm ERR! gyp info using node-gyp@3.8.0
    npm ERR! gyp info using node@16.2.0 | win32 | x64
    npm ERR! gyp verb command rebuild []
    npm ERR! gyp verb command clean []
    npm ERR! gyp verb clean removing "build" directory
    npm ERR! gyp verb command configure []
    npm ERR! gyp verb check python checking for Python executable "python2" in the PATH
    npm ERR! gyp verb `which` failed Error: not found: python2
    npm ERR! gyp verb `which` failed     at getNotFoundError (D:\sb-app\node_modules\which\which.js:13:12)
    npm ERR! gyp verb `which` failed     at F (D:\sb-app\node_modules\which\which.js:68:19)
    npm ERR! gyp verb `which` failed     at E (D:\sb-app\node_modules\which\which.js:80:29)
    npm ERR! gyp verb `which` failed     at D:\sb-app\node_modules\which\which.js:89:16
    npm ERR! gyp verb `which` failed     at D:\sb-app\node_modules\isexe\index.js:42:5
    npm ERR! gyp verb `which` failed     at D:\sb-app\node_modules\isexe\windows.js:36:5
    npm ERR! gyp verb `which` failed     at FSReqCallback.oncomplete (node:fs:194:21)
    npm ERR! gyp verb `which` failed  python2 Error: not found: python2
    npm ERR! gyp verb `which` failed     at getNotFoundError (D:\sb-app\node_modules\which\which.js:13:12)
    npm ERR! gyp verb `which` failed     at F (D:\sb-app\node_modules\which\which.js:68:19)
    npm ERR! gyp verb `which` failed     at E (D:\sb-app\node_modules\which\which.js:80:29)
    npm ERR! gyp verb `which` failed     at D:\sb-app\node_modules\which\which.js:89:16
    npm ERR! gyp verb `which` failed     at D:\sb-app\node_modules\isexe\index.js:42:5
    npm ERR! gyp verb `which` failed     at D:\sb-app\node_modules\isexe\windows.js:36:5
    npm ERR! gyp verb `which` failed     at FSReqCallback.oncomplete (node:fs:194:21) {
    npm ERR! gyp verb `which` failed   code: 'ENOENT'
    npm ERR! gyp verb `which` failed }
    npm ERR! gyp verb check python checking for Python executable "python" in the PATH
    npm ERR! gyp verb `which` succeeded python C:\Python39\python.EXE
    npm ERR! gyp ERR! configure error
    npm ERR! gyp ERR! stack Error: Command failed: C:\Python39\python.EXE -c import sys; print "%s.%s.%s" % sys.version_info[:3];
    npm ERR! gyp ERR! stack   File "<string>", line 1
    npm ERR! gyp ERR! stack     import sys; print "%s.%s.%s" % sys.version_info[:3];
    npm ERR! gyp ERR! stack                       ^
    npm ERR! gyp ERR! stack SyntaxError: invalid syntax
    npm ERR! gyp ERR! stack
    npm ERR! gyp ERR! stack     at ChildProcess.exithandler (node:child_process:326:12)
    npm ERR! gyp ERR! stack     at ChildProcess.emit (node:events:365:28)
    npm ERR! gyp ERR! stack     at maybeClose (node:internal/child_process:1067:16)
    npm ERR! gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:301:5)
    npm ERR! gyp ERR! System Windows_NT 10.0.19042
    npm ERR! gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "D:\\sb-app\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
    npm ERR! gyp ERR! cwd D:\sb-app\node_modules\node-sass
    npm ERR! gyp ERR! node -v v16.2.0
    npm ERR! gyp ERR! node-gyp -v v3.8.0
    npm ERR! gyp ERR! not ok
    npm ERR! Build failed with error code: 1

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Ionutz\AppData\Local\npm-cache\_logs\2021-05-21T08_51_40_333Z-debug.log

我不知道该怎么办我也尝试安装 node-sass 但没有成功

【问题讨论】:

    标签: node.js angular npm-install node-sass


    【解决方案1】:

    npm 错误有时可能非常(可以说是过于)冗长。错误的有趣部分是:

    npm ERR! gyp verb check python checking for Python executable "python2" in the PATH
    

    您尝试安装的软件包有一个使用 gyp 在本地编译的本机部分,作为其工具的一部分,npm 需要 python2 来执行构建。
    您需要确保已安装 python2,并且可执行文件是路径的一部分。

    或者,如果你安装了 python,但它的命名不同,你可以通过调用告诉 npm 使用哪个可执行文件

    npm config set python /path/to/your/python
    

    【讨论】:

    • 我这样做了,现在在尝试启动 Angular 项目时遇到了一个新问题 C:\Users\Ionutz\AppData\Roaming\npm/node_modules/node/bin/node: 第 1 行:这个:找不到命令,我使用了 git bash,当我用 powershell 启动它时它工作了
    【解决方案2】:

    我昨天遇到了类似的问题。我通过确保在默认目录中下载了 python 并安装 Windows Build Tools 来修复它,因为 node-sass 需要 node-gyp,而 node-gyp 反过来需要 Windows Build Tools。

    您可以使用管理 shell 下载它,但同样容易转到此page,然后找到并下载“Build Tools for Visual Studio”。 here 也可以找到一个很好的视频来解释这个过程。如前所述,您可以使用 powershell 安装,前提是它以管理员身份运行,这个过程可以在它的 npm 页面here 上找到。

    这可能值得删除您的节点模块文件夹并在完成后重新运行 npm install。

    【讨论】:

      【解决方案3】:

      我遇到了类似的问题。尝试删除 package-lock.json 然后重新运行 'npm install'。

      【讨论】:

        猜你喜欢
        • 2020-09-10
        • 1970-01-01
        • 2022-01-06
        • 2020-05-30
        • 2020-07-16
        • 1970-01-01
        • 1970-01-01
        • 2020-02-20
        • 1970-01-01
        相关资源
        最近更新 更多