SharePoint / sp-dev-docs

SharePoint & Viva Connections Developer Documentation
https://docs.microsoft.com/en-us/sharepoint/dev/
Creative Commons Attribution 4.0 International
1.25k stars 1.01k forks source link

Node v1.18.2 throws this error #9746

Open zoh-akh opened 5 months ago

zoh-akh commented 5 months ago

Even though the documentation clearly mentions that the newly supported version for Node.js is v1.18, I get the following error when running gulp serve

Error: Your dev environment is running NodeJS version v18.20.3 which does not meet the requirements for running this tool. This tool requires a version of NodeJS that matches >=12.13.0 <13.0.0 || >=14.15.0 <15.0.0 || >=16.13.0 <17.0.0

Am I missing something?


Document Details

Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.

andrewconnell commented 5 months ago

Please clarify... there's no such Nodejs version v1.18... are you mixing SPFx & Node versions?

Share some context on your environment, like:

zoh-akh commented 5 months ago

Oh, sorry that was a mistake. I meant Node.js v18. When I run gulp serve I get the error as I mentioned above. Here is my node version output: Run: node -v v18.20.3

Run: npm list -g --depth=0 ├── @microsoft/generator-sharepoint@1.19.0 ├── gulp-cli@3.0.0 └── yo@5.0.0

package.json: { "name": "welcome-HW", "version": "0.0.1", "private": true, "engines": { "node": ">=16.13.0 <17.0.0" }, "main": "lib/index.js", "scripts": { "build": "gulp bundle", "clean": "gulp clean", "test": "gulp test" }, "dependencies": { "@microsoft/sp-component-base": "1.17.3", "@microsoft/sp-core-library": "1.17.3", "@microsoft/sp-lodash-subset": "1.17.3", "@microsoft/sp-office-ui-fabric-core": "1.17.3", "@microsoft/sp-property-pane": "1.17.3", "@microsoft/sp-webpart-base": "1.17.3", "tslib": "2.3.1" }, "devDependencies": { "@fluentui/react": "^7.199.1", "@microsoft/eslint-config-spfx": "1.17.3", "@microsoft/eslint-plugin-spfx": "1.17.3", "@microsoft/rush-stack-compiler-4.5": "0.5.0", "@microsoft/sp-build-web": "1.17.3", "@microsoft/sp-module-interfaces": "1.17.3", "@rushstack/eslint-config": "2.5.1", "@types/webpack-env": "~1.15.2", "ajv": "^6.12.5", "eslint": "8.7.0", "gulp": "4.0.2", "typescript": "4.5.5" } }

andrewconnell commented 5 months ago

The project is using SPFx v1.17.3. That version only supports Node.js v16, which is what this line in your package.json is saying:

{
  ...
  "engines": {
    "node": ">=16.13.0 <17.0.0"
  }
  ...
}

So, your options are to:

  1. Downgrade your Node.js install > Node.js v16
  2. Upgrade your SPFx project to a version that supports Node.js v18. That's SPFx v1.18.0+
  3. Use NVM to have multiple Node.js installs

FWIW, I'd go with the last option above. Learn more: Manage Multiple Node.js Version Installs with NVM

stevebeauge commented 3 months ago

If it helps, using PNPM instead of NPM allow to specify the node's version inside .npmrc.

Details : https://pnpm.io/npmrc#use-node-version.

I use the settings for some years now, and I moved out of any node version manager.

Just install latest node LTS, and specify in each project the required node version.

That said, I strongly advocate using pnpm instead of npm. Not only because of the speed and disk usage improvements but also because PNPM requires you to have clean dependencies (see https://rushjs.io/pages/advanced/phantom_deps/ and https://rushjs.io/pages/advanced/npm_doppelgangers/).