'Yeoman SPFx issue with installing @microsoft/sharepoint generator

I'm trying to learn how to use SPFx, however I'm falling down at the first step when it comes to running yo @microsoft/sharepoint.

I get the following error when running 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.

I have tried running npm install @microsoft/generator-sharepoint -g however this does not resolve the above error. It's also worth noting that I get a bunch of errors when running the install generator command:

    npm WARN EBADENGINE Unsupported engine {
    npm WARN EBADENGINE   package: '@microsoft/[email protected]',
    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/[email protected]',
    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 [email protected]: Please see https://github.com/lydell/urix#deprecated
    npm WARN deprecated [email protected]: this library is no longer supported
    npm WARN deprecated [email protected]: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies
    .
    npm WARN deprecated [email protected]: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies
    .
    npm WARN deprecated [email protected]: https://github.com/lydell/resolve-url#deprecated
    npm WARN deprecated [email protected]: The querystring API is considered Legacy. new code should use the URLSearchParams
     API instead.
    npm WARN deprecated [email protected]: 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 [email protected]: 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 [email protected]: 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 [email protected]: 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 [email protected]: 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 [email protected]: request has been deprecated, see https://github.com/request/request/issues/3142
    npm WARN deprecated @opentelemetry/[email protected]: Package renamed to @opentelemetry/api, see https://github.com/open-telem
    etry/opentelemetry-js
    npm WARN deprecated [email protected]: This SVGO version is no longer supported. Upgrade to     v2.x.x.
    npm WARN deprecated [email protected]: 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%\AppData\Roaming\npm\node_modules\@microsoft\generator-sharepoint\node_modules\node-sas
    s
    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     C:\Users\%username%\AppData\Roaming\npm\node_modules\@microsoft\gene
rator-sharepoint\node_modules\node-gyp\bin\node-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 [email protected]
    npm ERR! gyp info using [email protected] | 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%\AppData\Roaming\npm\node_modules\@microsof
t\generator-sharepoint\node_modules\which\which.js:13:12)
    npm ERR! gyp verb `which` failed     at F     (C:\Users\%username%\AppData\Roaming\npm\node_modules\@microsoft\generator-sha
    repoint\node_modules\which\which.js:68:19)
    npm ERR! gyp verb `which` failed     at E     (C:\Users\%username%\AppData\Roaming\npm\node_modules\@microsoft\generator-sha
    repoint\node_modules\which\which.js:80:29)
    npm ERR! gyp verb `which` failed     at     C:\Users\%username%\AppData\Roaming\npm\node_modules\@microsoft\generator-sharep
        oint\node_modules\which\which.js:89:16
    npm ERR! gyp verb `which` failed     at     C:\Users\%username%\AppData\Roaming\npm\node_modules\@microsoft\generator-sharep
    oint\node_modules\isexe\index.js:42:5
    npm ERR! gyp verb `which` failed     at     C:\Users\%username%\AppData\Roaming\npm\node_modules\@microsoft\generator-sharep
    oint\node_modules\isexe\windows.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%\AppData\Roaming\npm\node_modules\@microsof
    t\generator-sharepoint\node_modules\which\which.js:13:12)
    npm ERR! gyp verb `which` failed     at F         (C:\Users\%username%\AppData\Roaming\npm\node_modules\@microsoft\generator-sha
    repoint\node_modules\which\which.js:68:19)
    npm ERR! gyp verb `which` failed     at E     (C:\Users\%username%\AppData\Roaming\npm\node_modules\@microsoft\generator-sha
    repoint\node_modules\which\which.js:80:29)
    npm ERR! gyp verb `which` failed     at     C:\Users\%username%\AppData\Roaming\npm\node_modules\@microsoft\generator-sharep
    oint\node_modules\which\which.js:89:16
    npm ERR! gyp verb `which` failed     at     C:\Users\%username%\AppData\Roaming\npm\node_modules\@microsoft\generator-sharep
    oint\node_modules\isexe\index.js:42:5
    npm ERR! gyp verb `which` failed     at     C:\Users\%username%\AppData\Roaming\npm\node_modules\@microsoft\generator-sharep
    oint\node_modules\isexe\windows.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 Files\Python310\python.EXE
    npm ERR! gyp ERR! configure error
    npm ERR! gyp ERR! stack Error: Command failed: C:\Program Files\Python310\python.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%\AppData\Roaming\npm\node_modules\@microsoft\generator-    sharepoint\node_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%\AppData\Local\npm-cache\_logs\2021-11-12T03_25_38_209Z-debug.log

Could anyone please help troubleshoot this with me? I'm not sure what is causing the issues with the @microsoft/sharepoint generator install, but something is seemingly preventing it from installing properly.

Any help is greatly appreciated.

Many thanks,

Alex.



Solution 1:[1]

Turns out the issue is that I was using the latest version of Node.js (v16.13.0) when I needed to be using a supported version (v14.15.0)

Solution 2:[2]

Node v14 is the key here. Atleast working for me by downloading the node v14.18.

Solution 3:[3]

1.Install the latest version of Node.js LTS v14.

2.install the latest version of npm: npm i -g npm@next

3.run the following in your cmd window or commander window:

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

Solution 4:[4]

Try different versions of Node v14. Mine did not work for node 14.17 but worked for v14.19

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 alexthannah
Solution 2 Zeeshan Ahmed
Solution 3 Allen_MSFT
Solution 4 Thanura Marapana