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



我正在努力学习如何使用SPFx,但在运行yo @microsoft/sharepoint的第一步我就失败了。

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

Error @microsoft/sharepoint
You don't seem to have a generator with the name “@microsoft/sharepoint” installed.
But help is on the way:
You can see available generators via npm search yeoman-generator or via http://yeoman.io/generators/.
Install them with npm install @microsoft/generator-sharepoint.
To see all your installed generators run yo --generators. Adding the --help option will also show subgenerators.
If yo cannot find the generator, run yo doctor to troubleshoot your system.

我已经尝试运行npm install @microsoft/generator-sharepoint -g,但这并不能解决上述错误。同样值得注意的是,我在运行installgenerator命令时遇到了一堆错误:

npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: '@microsoft/generator-sharepoint@1.13.0',
npm WARN EBADENGINE   required: { node: '>=12.13.0 <13.0.0 || >=14.15.0 <15.0.0' },
npm WARN EBADENGINE   current: { node: 'v16.13.0', npm: '8.1.0' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: '@microsoft/sp-module-interfaces@1.13.0',
npm WARN EBADENGINE   required: { node: '>=12.13.0 <13.0.0 || >=14.15.0 <15.0.0' },
npm WARN EBADENGINE   current: { node: 'v16.13.0', npm: '8.1.0' }
npm WARN EBADENGINE }
npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated har-validator@5.1.5: this library is no longer supported
npm WARN deprecated chokidar@2.1.8: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies
.
npm WARN deprecated chokidar@2.1.8: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies
.
npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated querystring@0.2.0: The querystring API is considered Legacy. new code should use the URLSearchParams
API instead.
npm WARN deprecated uuid@3.1.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain
circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain
circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain
circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain
circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain
circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated @opentelemetry/types@0.2.0: Package renamed to @opentelemetry/api, see https://github.com/open-telem
etry/opentelemetry-js
npm WARN deprecated svgo@1.3.2: This SVGO version is no longer supported. Upgrade to     v2.x.x.
npm WARN deprecated tar@2.2.2: This version of tar is no longer supported, and will not receive security updates. Please
upgrade asap.
npm ERR! code 1
npm ERR! path     C:Users%username%AppDataRoamingnpmnode_modules@microsoftgenerator-sharepointnode_modulesnode-sas
s
npm ERR! command failed
npm ERR! command C:windowssystem32cmd.exe /d /s /c node scripts/build.js
npm ERR! Building: C:Program Filesnodejsnode.exe     C:Users%username%AppDataRoamingnpmnode_modules@microsoftgene
rator-sharepointnode_modulesnode-gypbinnode-gyp.js rebuild --verbose --libsass_ext= -    -libsass_cflags= --libsass_ldfl
ags= --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       'C:\Users\%username%\AppData\Roaming\npm\node_modules\@microsoft\generator-    sharepoint\n
ode_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.13.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     (C:Users%username%AppDataRoamingnpmnode_modules@microsof
tgenerator-sharepointnode_moduleswhichwhich.js:13:12)
npm ERR! gyp verb `which` failed     at F     (C:Users%username%AppDataRoamingnpmnode_modules@microsoftgenerator-sha
repointnode_moduleswhichwhich.js:68:19)
npm ERR! gyp verb `which` failed     at E     (C:Users%username%AppDataRoamingnpmnode_modules@microsoftgenerator-sha
repointnode_moduleswhichwhich.js:80:29)
npm ERR! gyp verb `which` failed     at     C:Users%username%AppDataRoamingnpmnode_modules@microsoftgenerator-sharep
ointnode_moduleswhichwhich.js:89:16
npm ERR! gyp verb `which` failed     at     C:Users%username%AppDataRoamingnpmnode_modules@microsoftgenerator-sharep
ointnode_modulesisexeindex.js:42:5
npm ERR! gyp verb `which` failed     at     C:Users%username%AppDataRoamingnpmnode_modules@microsoftgenerator-sharep
ointnode_modulesisexewindows.js:36:5
npm ERR! gyp verb `which` failed     at FSReqCallback.oncomplete (node:fs:198:21)
npm ERR! gyp verb `which` failed  python2 Error: not found: python2
npm ERR! gyp verb `which` failed     at getNotFoundError     (C:Users%username%AppDataRoamingnpmnode_modules@microsof
tgenerator-sharepointnode_moduleswhichwhich.js:13:12)
npm ERR! gyp verb `which` failed     at F         (C:Users%username%AppDataRoamingnpmnode_modules@microsoftgenerator-sha
repointnode_moduleswhichwhich.js:68:19)
npm ERR! gyp verb `which` failed     at E     (C:Users%username%AppDataRoamingnpmnode_modules@microsoftgenerator-sha
repointnode_moduleswhichwhich.js:80:29)
npm ERR! gyp verb `which` failed     at     C:Users%username%AppDataRoamingnpmnode_modules@microsoftgenerator-sharep
ointnode_moduleswhichwhich.js:89:16
npm ERR! gyp verb `which` failed     at     C:Users%username%AppDataRoamingnpmnode_modules@microsoftgenerator-sharep
ointnode_modulesisexeindex.js:42:5
npm ERR! gyp verb `which` failed     at     C:Users%username%AppDataRoamingnpmnode_modules@microsoftgenerator-sharep
ointnode_modulesisexewindows.js:36:5
npm ERR! gyp verb `which` failed     at FSReqCallback.oncomplete (node:fs:198: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:Program FilesPython310python.EXE
npm ERR! gyp ERR! configure error
npm ERR! gyp ERR! stack Error: Command failed: C:Program FilesPython310python.EXE     -c import sys; print "%s.%s.%s" % s
ys.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: Missing parentheses in call to 'print'. Did you     mean print(...)?
npm ERR! gyp ERR! stack
npm ERR! gyp ERR! stack     at ChildProcess.exithandler (node:child_process:397:12)
npm ERR! gyp ERR! stack     at ChildProcess.emit (node:events:390:28)
npm ERR! gyp ERR! stack     at maybeClose (node:internal/child_process:1064: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.14393
npm ERR! gyp ERR! command "C:\Program Files\nodejs\node.exe"     "C:\Users\%username%\AppData\Roaming\npm\node_modu
les\@microsoft\generator-sharepoint\node_modules\node-gyp\bin\node-gyp.js"     "rebuild" "--verbose" "--libsass_ext="
"--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
npm ERR! gyp ERR! cwd     C:Users%username%AppDataRoamingnpmnode_modules@microsoftgenerator-    sharepointnode_modules
node-sass
npm ERR! gyp ERR! node -v v16.13.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%username%AppDataLocalnpm-cache_logs2021-11-12T03_25_38_209Z-debug.log

有人能帮我解决这个问题吗?我不确定是什么原因导致@microsoft/sharepoint生成器安装出现问题,但似乎有一些东西阻碍了它的正确安装。

非常感谢您的帮助。

非常感谢,

亚历克斯。

问题是,当我需要使用支持的版本(v14.15.0(时,我使用的是最新版本的Node.js(v16.13.0(

节点v14是这里的关键。至少通过下载节点v14.18为我工作。

1.安装最新版本的Node.js LTS v14。

2.安装最新版本的npm:npm i-gnpm@next

3.在命令窗口或命令窗口中运行以下命令:

npm uninstall -g chalk
npm uninstall -g loadash
npm uninstall -g tar-fs
npm uninstall -g update-notifier
npm uninstall -g yeoman-generator
npm uninstall -g yosay
npm uninstall -g yo
npm uninstall -g gulp
npm uninstall -g @microsoft/generator-sharepoint
npm install -g chalk
npm install -g loadash
npm install -g tar-fs
npm install -g update-notifier
npm install -g yeoman-generator
npm install -g yosay
npm install -g yo
npm install -g gulp

尝试不同版本的Node v14。Mine不适用于节点14.17,但适用于v14.19

最新更新