13

After installation of Node v10.16.1 and installation of gulp and yo (Everything looks alright !) it fails on command yo @microsoft/sharepoint with TypeError: lookups.flatMap is not a function

C:\Users\MYNAME\AppData\Roaming\npm\node_modules\yo\node_modules\yeoman-environment\lib\resolver.js:70
    filePatterns: lookups.flatMap(prefix => [`${prefix}/*/index.ts`, `${prefix}/*/index.js`]),
                          ^

TypeError: lookups.flatMap is not a function
    at Environment.resolver.lookup (C:\Users\MYNAME\AppData\Roaming\npm\node_modules\yo\node_modules\yeoman-environment\lib\resolver.js:70:27)
    at init (C:\Users\MYNAME\AppData\Roaming\npm\node_modules\yo\lib\cli.js:130:7)
    at pre (C:\Users\MYNAME\AppData\Roaming\npm\node_modules\yo\lib\cli.js:89:3)
    at Object.<anonymous> (C:\Users\MYNAME\AppData\Roaming\npm\node_modules\yo\lib\cli.js:219:3)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)

I am a beginner ! Few days ago it worked , then I installed nvm (following a microsoft instruction to swap node v8 to node v10) and then problems started and i uninstalled nvm, node v8 and v10 en reinstalled node v10. The TypeError returns. Perhaps something to do with path ?
Any idea ? thx

thb
  • 167
  • 1
  • 1
  • 7

4 Answers4

26

I resolved this by downgrading my gulp and yeoman versions.

First checked to see what I had installed:

npm list -g --depth=0

Output:

+-- @microsoft/generator-sharepoint@1.11.0
+-- gulp@4.0.2
+-- npm@6.14.12
+-- windows-build-tools@5.2.2
-- yo@4.0.0

So I uninstalled both gulp and yeoman:

npm uninstall -g gulp
npm uninstall -g yo

Then installed older versions:

npm install -g gulp@3.9.1
npm install -g yo@3.1.0

Then was able to generate the SharePoint framework project successfully after running:

yo @microsoft/sharepoint

Once it completed, I was able to run the following from inside the SharePoint framework project directory to launch the local workbench:

gulp serve

Note: If if not already done so once, you need to generate a development certificate inside the SharePoint framework project directory:

gulp trust-dev-cert
slyfox
  • 276
  • 3
  • 2
11

I believe you should upgrade node.js to v14, as stated in Microsoft official guide:

Install the latest version of Node.js LTS v14.
This version is the currently recommended version of Node.js to use with the SharePoint Framework

Node v10 is EOL in few days (tomorrow, in fact), so it is unsafe to use it.

I faced the same issue today while scaffolding a new webpart, and I solved by upgrading node from v10 to v14.

Another suggestion is to avoid installing global npm packages if you are going to use it just once (for scaffolding, for example); I usually use npx to download on the fly yo and the microsoft generator, so I always use the latest available versions:

$ npx -p yo -p @microsoft/generator-sharepoint -c "yo @microsoft/sharepoint"

Hope this can help, bye!

Tilt
  • 647
  • 1
  • 10
  • 23
  • don't know why, my first row containing "Hi @thb" is deleted when I try to post my answer (?); if I write 'welcome' instead of 'Hi', all is fine. – Tilt Apr 29 '21 at 20:14
  • 1
    After upgrading to node 14, issue got resolved. Also installed gulp@3.9.1 and yo@3.1.0 – JEEVAN GEORGE ANTONY Jun 15 '21 at 10:41
  • If you upgrade to Node 14, be careful if you rely on @pnp/generator-spfx and develop your webparts in anything other than React. – Ben Hoffmann Sep 09 '21 at 17:23
1

First try to uninstall both gulp and yeoman:
to uninstall run these commands-->

npm uninstall -g gulp
npm uninstall -g yo

Then installed older versions:
to install run these commands-->

npm install -g gulp@3.9.1
npm install -g yo@3.1.0

Then was able to generate the SharePoint framework project successfully after running:

yo @microsoft/sharepoint
Nimantha
  • 6,405
  • 6
  • 28
  • 69
1

Check version list if same or not:

npm list -g --depth=0

+-- @microsoft/generator-sharepoint@1.11.0
+-- gulp@3.9.1
+-- gulp-cli@2.3.0
+-- yarn@1.22.17
+-- yo@3.1.0

Run below commands to uninstall:

npm uninstall -g gulp
npm uninstall -g yo

Run below commands:

npm install -g gulp@3.9.1
npm install -g yo@3.1.0
npm uninstall -g @microsoft/generator-sharepoint

Then install a previous version:

npm install -g @microsoft/generator-sharepoint@1.11.0
Nimantha
  • 6,405
  • 6
  • 28
  • 69