Yeoman SharePoint Framework webpart generator error

2.8k views Asked by At

I'm new to Yeoman so any help would really be useful.

When attempting to use the Yeoman SharePoint Framework webpart generator I get the following error:

events.js:160
      throw er; // Unhandled 'error' event
      ^

Error: Cannot find "package.json" file required by this generator
    at WebpartGenerator.get [as packageJson] (/usr/local/lib/node_modules/@microsoft/generator-sharepoint/lib/common/BaseGenerator.js:45:23)
    at WebpartGenerator.BaseGenerator.ensureDependencyGroup (/usr/local/lib/node_modules/@microsoft/generator-sharepoint/lib/common/BaseGenerator.js:96:18)
    at WebpartGenerator.BaseComponentGenerator.configuring (/usr/local/lib/node_modules/@microsoft/generator-sharepoint/lib/generators/component/BaseComponentGenerator.js:95:14)
    at WebpartGenerator.configuring (/usr/local/lib/node_modules/@microsoft/generator-sharepoint/lib/generators/webpart/index.js:43:38)
    at Object.<anonymous> (/usr/local/lib/node_modules/@microsoft/generator-sharepoint/node_modules/yeoman-generator/lib/index.js:408:23)
    at /usr/local/lib/node_modules/@microsoft/generator-sharepoint/node_modules/run-async/index.js:25:25
    at /usr/local/lib/node_modules/@microsoft/generator-sharepoint/node_modules/run-async/index.js:24:19
    at /usr/local/lib/node_modules/@microsoft/generator-sharepoint/node_modules/yeoman-generator/lib/index.js:409:9
    at runCallback (timers.js:672:20)
    at tryOnImmediate (timers.js:645:5)
2

There are 2 answers

6
Gautam Sheth On

Couple of things that you need to check:

1) Ensure that you are using the Node.js LTS version. If unsure, uninstall the Node js, and download it from here - Node v6.11

2) Ensure that your NPM version is 3.x. SPFx is currently not compatible with NPM 5.

You can check that by running the npm -v command in the command line.

If its version 5, you can downgrade it by running the below command:

npm install -g npm3

3) Once done, you can install the latest yeoman template of spfx as below:

npm install @microsoft/generator-sharepoint@latest -g

4) After that, you can run the yo @microsoft/sharepoint command to create SPFx webpart

0
Kengo Mori On

This is reproduced in the following way.

  1. Generate SPFx Project in Parent folder.
  2. Make sub folder (ex. Sub1) and move all the visible files to that folder using Finder. (Note. All the hidden files that starts with . are left in the parent folder with this step)
  3. Make another folder (ex. Sub2) and generate SPFx project again. And here this error is shown.

In step 2, it was necessary to move all the hidden files to the child folder. Anyway, workaround of this issue is to use unrelated brand new folder such as Parent2.

Parent (Sub1, Sub2), Parent2