Yeoman SPFx 安装 @microsoft/sharepoint 生成器时出现问题

ale*_*nah 2 java sharepoint yeoman yeoman-generator spfx

我正在尝试学习如何使用 SPFx,但是在跑步的第一步中我就失败了yo @microsoft/sharepoint

\n

运行时出现以下错误yo @microsoft/sharepoint

\n
Error @microsoft/sharepoint\n\nYou don't seem to have a generator with the name \xe2\x80\x9c@microsoft/sharepoint\xe2\x80\x9d installed.\nBut help is on the way:\n\nYou can see available generators via npm search yeoman-generator or via http://yeoman.io/generators/.\nInstall them with npm install @microsoft/generator-sharepoint.\n\nTo see all your installed generators run yo --generators. Adding the --help option will also show subgenerators.\n\nIf yo cannot find the generator, run yo doctor to troubleshoot your system.\n
Run Code Online (Sandbox Code Playgroud)\n

我尝试过运行npm install @microsoft/generator-sharepoint -g,但这并不能解决上述错误。还值得注意的是,我在运行安装生成器命令时遇到了一堆错误:

\n
    npm WARN EBADENGINE Unsupported engine {\n    npm WARN EBADENGINE   package: '@microsoft/generator-sharepoint@1.13.0',\n    npm WARN EBADENGINE   required: { node: '>=12.13.0 <13.0.0 || >=14.15.0 <15.0.0' },\n    npm WARN EBADENGINE   current: { node: 'v16.13.0', npm: '8.1.0' }\n    npm WARN EBADENGINE }\n    npm WARN EBADENGINE Unsupported engine {\n    npm WARN EBADENGINE   package: '@microsoft/sp-module-interfaces@1.13.0',\n    npm WARN EBADENGINE   required: { node: '>=12.13.0 <13.0.0 || >=14.15.0 <15.0.0' },\n    npm WARN EBADENGINE   current: { node: 'v16.13.0', npm: '8.1.0' }\n    npm WARN EBADENGINE }\n    npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated\n    npm WARN deprecated har-validator@5.1.5: this library is no longer supported\n    npm WARN deprecated chokidar@2.1.8: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies\n    .\n    npm WARN deprecated chokidar@2.1.8: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies\n    .\n    npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated\n    npm WARN deprecated querystring@0.2.0: The querystring API is considered Legacy. new code should use the URLSearchParams\n     API instead.\n    npm WARN deprecated uuid@3.1.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain\n     circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.\n    npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain\n     circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.\n    npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain\n     circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.\n    npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain\n     circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.\n    npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain\n     circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.\n    npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142\n    npm WARN deprecated @opentelemetry/types@0.2.0: Package renamed to @opentelemetry/api, see https://github.com/open-telem\n    etry/opentelemetry-js\n    npm WARN deprecated svgo@1.3.2: This SVGO version is no longer supported. Upgrade to     v2.x.x.\n    npm WARN deprecated tar@2.2.2: This version of tar is no longer supported, and will not receive security updates. Please\n     upgrade asap.\n    npm ERR! code 1\n    npm ERR! path     C:\\Users\\%username%\\AppData\\Roaming\\npm\\node_modules\\@microsoft\\generator-sharepoint\\node_modules\\node-sas\n    s\n    npm ERR! command failed\n    npm ERR! command C:\\windows\\system32\\cmd.exe /d /s /c node scripts/build.js\n    npm ERR! Building: C:\\Program Files\\nodejs\\node.exe     C:\\Users\\%username%\\AppData\\Roaming\\npm\\node_modules\\@microsoft\\gene\nrator-sharepoint\\node_modules\\node-gyp\\bin\\node-gyp.js rebuild --verbose --libsass_ext= -    -libsass_cflags= --libsass_ldfl\n    ags= --libsass_library=\n    npm ERR! gyp info it worked if it ends with ok\n    npm ERR! gyp verb cli [\n    npm ERR! gyp verb cli   'C:\\\\Program Files\\\\nodejs\\\\node.exe',\n    npm ERR! gyp verb cli       'C:\\\\Users\\\\%username%\\\\AppData\\\\Roaming\\\\npm\\\\node_modules\\\\@microsoft\\\\generator-    sharepoint\\\\n\n    ode_modules\\\\node-gyp\\\\bin\\\\node-gyp.js',\n    npm ERR! gyp verb cli   'rebuild',\n    npm ERR! gyp verb cli   '--verbose',\n    npm ERR! gyp verb cli   '--libsass_ext=',\n    npm ERR! gyp verb cli   '--libsass_cflags=',\n    npm ERR! gyp verb cli   '--libsass_ldflags=',\n    npm ERR! gyp verb cli   '--libsass_library='\n    npm ERR! gyp verb cli ]\n    npm ERR! gyp info using node-gyp@3.8.0\n    npm ERR! gyp info using node@16.13.0 | win32 | x64\n    npm ERR! gyp verb command rebuild []\n    npm ERR! gyp verb command clean []\n    npm ERR! gyp verb clean removing "build" directory\n    npm ERR! gyp verb command configure []\n    npm ERR! gyp verb check python checking for Python executable "python2" in the PATH\n    npm ERR! gyp verb `which` failed Error: not found: python2\n    npm ERR! gyp verb `which` failed     at getNotFoundError     (C:\\Users\\%username%\\AppData\\Roaming\\npm\\node_modules\\@microsof\nt\\generator-sharepoint\\node_modules\\which\\which.js:13:12)\n    npm ERR! gyp verb `which` failed     at F     (C:\\Users\\%username%\\AppData\\Roaming\\npm\\node_modules\\@microsoft\\generator-sha\n    repoint\\node_modules\\which\\which.js:68:19)\n    npm ERR! gyp verb `which` failed     at E     (C:\\Users\\%username%\\AppData\\Roaming\\npm\\node_modules\\@microsoft\\generator-sha\n    repoint\\node_modules\\which\\which.js:80:29)\n    npm ERR! gyp verb `which` failed     at     C:\\Users\\%username%\\AppData\\Roaming\\npm\\node_modules\\@microsoft\\generator-sharep\n        oint\\node_modules\\which\\which.js:89:16\n    npm ERR! gyp verb `which` failed     at     C:\\Users\\%username%\\AppData\\Roaming\\npm\\node_modules\\@microsoft\\generator-sharep\n    oint\\node_modules\\isexe\\index.js:42:5\n    npm ERR! gyp verb `which` failed     at     C:\\Users\\%username%\\AppData\\Roaming\\npm\\node_modules\\@microsoft\\generator-sharep\n    oint\\node_modules\\isexe\\windows.js:36:5\n    npm ERR! gyp verb `which` failed     at FSReqCallback.oncomplete (node:fs:198:21)\n    npm ERR! gyp verb `which` failed  python2 Error: not found: python2\n    npm ERR! gyp verb `which` failed     at getNotFoundError     (C:\\Users\\%username%\\AppData\\Roaming\\npm\\node_modules\\@microsof\n    t\\generator-sharepoint\\node_modules\\which\\which.js:13:12)\n    npm ERR! gyp verb `which` failed     at F         (C:\\Users\\%username%\\AppData\\Roaming\\npm\\node_modules\\@microsoft\\generator-sha\n    repoint\\node_modules\\which\\which.js:68:19)\n    npm ERR! gyp verb `which` failed     at E     (C:\\Users\\%username%\\AppData\\Roaming\\npm\\node_modules\\@microsoft\\generator-sha\n    repoint\\node_modules\\which\\which.js:80:29)\n    npm ERR! gyp verb `which` failed     at     C:\\Users\\%username%\\AppData\\Roaming\\npm\\node_modules\\@microsoft\\generator-sharep\n    oint\\node_modules\\which\\which.js:89:16\n    npm ERR! gyp verb `which` failed     at     C:\\Users\\%username%\\AppData\\Roaming\\npm\\node_modules\\@microsoft\\generator-sharep\n    oint\\node_modules\\isexe\\index.js:42:5\n    npm ERR! gyp verb `which` failed     at     C:\\Users\\%username%\\AppData\\Roaming\\npm\\node_modules\\@microsoft\\generator-sharep\n    oint\\node_modules\\isexe\\windows.js:36:5\n    npm ERR! gyp verb `which` failed     at FSReqCallback.oncomplete (node:fs:198:21) {\n    npm ERR! gyp verb `which` failed   code: 'ENOENT'\n    npm ERR! gyp verb `which` failed }\n    npm ERR! gyp verb check python checking for Python executable "python" in the PATH\n    npm ERR! gyp verb `which` succeeded python C:\\Program Files\\Python310\\python.EXE\n    npm ERR! gyp ERR! configure error\n    npm ERR! gyp ERR! stack Error: Command failed: C:\\Program Files\\Python310\\python.EXE     -c import sys; print "%s.%s.%s" % s\n    ys.version_info[:3];\n    npm ERR! gyp ERR! stack   File "<string>", line 1\n    npm ERR! gyp ERR! stack     import sys; print "%s.%s.%s" % sys.version_info[:3];\n    npm ERR! gyp ERR! stack                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n    npm ERR! gyp ERR! stack SyntaxError: Missing parentheses in call to 'print'. Did you     mean print(...)?\n    npm ERR! gyp ERR! stack\n    npm ERR! gyp ERR! stack     at ChildProcess.exithandler (node:child_process:397:12)\n    npm ERR! gyp ERR! stack     at ChildProcess.emit (node:events:390:28)\n    npm ERR! gyp ERR! stack     at maybeClose (node:internal/child_process:1064:16)\n    npm ERR! gyp ERR! stack     at Process.ChildProcess._handle.onexit     (node:internal/child_process:301:5)\n    npm ERR! gyp ERR! System Windows_NT 10.0.14393\n    npm ERR! gyp ERR! command "C:\\\\Program Files\\\\nodejs\\\\node.exe"     "C:\\\\Users\\\\%username%\\\\AppData\\\\Roaming\\\\npm\\\\node_modu\n    les\\\\@microsoft\\\\generator-sharepoint\\\\node_modules\\\\node-gyp\\\\bin\\\\node-gyp.js"     "rebuild" "--verbose" "--libsass_ext="\n    "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="\n    npm ERR! gyp ERR! cwd     C:\\Users\\%username%\\AppData\\Roaming\\npm\\node_modules\\@microsoft\\generator-    sharepoint\\node_modules\\\n    node-sass\n    npm ERR! gyp ERR! node -v v16.13.0\n    npm ERR! gyp ERR! node-gyp -v v3.8.0\n    npm ERR! gyp ERR! not ok\n    npm ERR! Build failed with error code: 1\n\n    npm ERR! A complete log of this run can be found in:\n    npm ERR!     C:\\Users\\%username%\\AppData\\Local\\npm-cache\\_logs\\2021-11-12T03_25_38_209Z-debug.log\n
Run Code Online (Sandbox Code Playgroud)\n

有人可以帮我解决这个问题吗?我不确定是什么导致了 @microsoft/sharepoint 生成器安装的问题,但似乎有什么东西阻止了它的正确安装。

\n

任何帮助是极大的赞赏。

\n

非常感谢,

\n

亚历克斯.

\n

ale*_*nah 6

事实证明,问题是当我需要使用受支持的版本 (v14.15.0) 时,我正在使用最新版本的 Node.js (v16.13.0)