Gatsby: 'gatsby' is not recognized as an internal or external command

Created on 17 Dec 2019  路  16Comments  路  Source: gatsbyjs/gatsby

I created a new gatsby project after installing Node, NPM, and Gatsby CLI. The project was working fine. I tried to deploy on Netlify which was unsuccessful as it couldn't find gatsby-plugin-styled-components and also threw Error: Build script returned non-zero exit code:1 I found on discussion forums to delete yarn.lock and package-lock.json file, I removed these files from my local machine and git repository. The project stopped working on the local machine as well and threw some errors so update npm, gatsby and gatsby-cli but now my machine doesn't recognize gatsby commands. How should I uninstall everything NPM, gatsby, gatsby-cli and start with the fresh installation?

My system details:

npm version 6.12.1
node version v12.13.1
npm view gatsby version = 2.18.12
npm gatsby -v = 6.12.1
npm gatsby-cli -v = 6.12.1

If try below command on cmd win 10, I get the following error:

gatsby -v = 'gatsby' is not recognized as an internal or external command,
operable program or batch file.

Please guide how to run my gatsby project.

stale? needs more info

Most helpful comment

For everyone experiencing this issue on windows, make sure you have got "C:Usersmtdev.MICHA-TECLASTAppDataRoamingnpm" and git added to the system's PATH environment variable. after adding it and reopening my command prompt, it all works fine again.

All 16 comments

Hi!

Can you share your repository so that other people can try it on their machines? I'd suggest deleting node_modules and your *.lock files, then rerun npm install. The last error message suggests that gatsby-cli isn't installed globally on your computer.

Hey!

To start fresh installation i recommend you the following steps to delete the existing files:
$ npm uninstall gatsby-cli

To reinstall:
npm install -g gatsby-cli

I think uninstalling npm would be pretty useless as i don鈥檛 think there is any problem with that.

Do I need to delete the entire node_modules folder and yarn.lock and package-lock.json files as well?

I tried with npm run start command and I receive these errors now:

https://prnt.sc/qc3e7s
https://prnt.sc/qc303p

Hey!

To start fresh installation i recommend you the following steps to delete the existing files:
$ npm uninstall gatsby-cli

To reinstall:
npm install -g gatsby-cli

I think uninstalling npm would be pretty useless as i don鈥檛 think there is any problem with that.

I tried this process but still can't run gatsby commands.

Environment:

System:
OS: Windows 10 10.0.18362
CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
Binaries:
Node: 12.13.1 - C:Program Filesnodejsnode.EXE
Yarn: 1.19.2 - C:Program Files (x86)Yarnbinyarn.CMD
npm: 6.13.4 - C:Program Filesnodejsnpm.CMD
Languages:
Python: 2.7.17 - C:Python27python.EXE
Browsers:
Edge: 44.18362.449.0
npmPackages:
gatsby: ^2.18.12 => 2.18.12
gatsby-image: ^2.2.36 => 2.2.36
gatsby-plugin-manifest: ^2.2.33 => 2.2.33
gatsby-plugin-offline: ^3.0.27 => 3.0.29
gatsby-plugin-page-transitions: ^1.0.8 => 1.0.8
gatsby-plugin-prefetch-google-fonts: ^1.4.3 => 1.4.3
gatsby-plugin-react-helmet: ^3.1.18 => 3.1.18
gatsby-plugin-sharp: ^2.3.8 => 2.3.8
gatsby-plugin-styled-components: ^3.1.16 => 3.1.16
gatsby-source-filesystem: ^2.1.40 => 2.1.42
gatsby-source-graphql: ^2.1.28 => 2.1.28
gatsby-source-wordpress: ^3.1.53 => 3.1.53
gatsby-transformer-sharp: ^2.3.9 => 2.3.9

Hi!

Can you share your repository so that other people can try it on their machines? I'd suggest deleting node_modules and your *.lock files, then rerun npm install. The last error message suggests that gatsby-cli isn't installed globally on your computer.

I tried this but still can't run gatsby commands. I tried to run with "npm run start" and it shows below error:

UNHANDLED REJECTION Cannot create as TypeComposer the following value: Date.

Error: Cannot create as TypeComposer the following value: Date.

  • SchemaComposer.js:365 SchemaComposer.createTempTC
    [expatguideturkey]/[graphql-compose]/lib/SchemaComposer.js:365:11

  • SchemaComposer.js:563 SchemaComposer.addAsComposer
    [expatguideturkey]/[graphql-compose]/lib/SchemaComposer.js:563:27

  • schema-composer.js:35 createSchemaComposer
    [expatguideturkey]/[gatsby]/dist/schema/schema-composer.js:35:18

  • index.js:133 Object.build
    [expatguideturkey]/[gatsby]/dist/schema/index.js:133:26

  • index.js:412 async module.exports
    [expatguideturkey]/[gatsby]/dist/bootstrap/index.js:412:3

  • develop.js:419 async module.exports
    [expatguideturkey]/[gatsby]/dist/commands/develop.js:419:7


Debug Log:

0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli 'C:\Program Files\nodejs\node.exe',
1 verbose cli 'C:\Program Files\Git\usr\local\node_modules\npm\bin\npm-cli.js',
1 verbose cli 'run',
1 verbose cli 'start'
1 verbose cli ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle [email protected]~prestart: [email protected]
6 info lifecycle [email protected]~start: [email protected]
7 verbose lifecycle [email protected]~start: unsafe-perm in lifecycle true
8 verbose lifecycle [email protected]~start: PATH: C:Program FilesGitusrlocalnode_modulesnpmnode_modulesnpm-lifecyclenode-gyp-bin;C:WindowsSystem32gatsby-projectsexpatguideturkeynode_modules.bin;C:Python27;C:Python27Scripts;C:Program Files (x86)IntelIntel(R) Management Engine ComponentsiCLS;C:Program FilesIntelIntel(R) Management Engine ComponentsiCLS;C:Windowssystem32;C:Windows;C:WindowsSystem32Wbem;C:WindowsSystem32WindowsPowerShellv1.0;C:Program Files (x86)IntelIntel(R) Management Engine ComponentsDAL;C:Program FilesIntelIntel(R) Management Engine ComponentsDAL;C:Program Files (x86)IntelIntel(R) Management Engine ComponentsIPT;C:Program FilesIntelIntel(R) Management Engine ComponentsIPT;C:Program Files (x86)NVIDIA CorporationPhysXCommon;C:WINDOWSsystem32;C:WINDOWS;C:WINDOWSSystem32Wbem;C:WINDOWSSystem32WindowsPowerShellv1.0;C:WINDOWSSystem32OpenSSH;C:Cmder;C:Program Files (x86)Gowbin;C:Gradlegradle-5.6.1bin;C:Program Filesnodejs;C:ProgramDatachocolateybin;C:Program Files (x86)Yarnbin;C:Program FilesGitcmd;C:Program FilesPuTTY;C:UsersEmmaAppDataLocalMicrosoftWindowsApps;C:UsersEmmaAppDataLocalProgramsMicr
9 verbose lifecycle [email protected]~start: CWD: C:WindowsSystem32gatsby-projectsexpatguideturkey
10 silly lifecycle [email protected]~start: Args: [ '/d /s /c', 'npm run develop' ]
11 silly lifecycle [email protected]~start: Returned: code: 1 signal: null
12 info lifecycle [email protected]~start: Failed to exec start script
13 verbose stack Error: [email protected] start: npm run develop
13 verbose stack Exit status 1
13 verbose stack at EventEmitter. (C:Program FilesGitusrlocalnode_modulesnpmnode_modulesnpm-lifecycleindex.js:332:16)
13 verbose stack at EventEmitter.emit (events.js:210:5)
13 verbose stack at ChildProcess. (C:Program FilesGitusrlocalnode_modulesnpmnode_modulesnpm-lifecyclelibspawn.js:55:14)
13 verbose stack at ChildProcess.emit (events.js:210:5)
13 verbose stack at maybeClose (internal/child_process.js:1021:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)
14 verbose pkgid [email protected]
15 verbose cwd C:WindowsSystem32gatsby-projectsexpatguideturkey
16 verbose Windows_NT 10.0.18362
17 verbose argv "C:\Program Files\nodejs\node.exe" "C:\Program Files\Git\usr\local\node_modules\npm\bin\npm-cli.js" "run" "start"
18 verbose node v12.13.1
19 verbose npm v6.13.4
20 error code ELIFECYCLE
21 error errno 1
22 error [email protected] start: npm run develop
22 error Exit status 1
23 error Failed at the [email protected] start script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

Hiya!

This issue has gone quiet. Spooky quiet. 馃懟

We get a lot of issues, so we currently close issues after 30 days of inactivity. It鈥檚 been at least 20 days since the last update here.
If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not stale" to keep this issue open!
As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing!

Thanks for being a part of the Gatsby community! 馃挭馃挏

@amreshabux Did you manage to get this up and running? The error messages suggest that you don't have gatsby-cli globally installed.

Running npm i -g gatsby-cli should fix this for you. In case it doesn't, please reopen and comment with more some info. Thanks!

@amreshabux Did you manage to get this up and running? The error messages suggest that you don't have gatsby-cli globally installed.

Running npm i -g gatsby-cli should fix this for you. In case it doesn't, please reopen and comment with more some info. Thanks!

yes thanks a lot. The issue is fixed now.

Plz tell me how did you solve this error? I am facing the same issue.

For everyone experiencing this issue on windows, make sure you have got "C:Usersmtdev.MICHA-TECLASTAppDataRoamingnpm" and git added to the system's PATH environment variable. after adding it and reopening my command prompt, it all works fine again.

Hi I am new with gatsby and programming. Can you help me with that too? I thing I have simmilar case when I try tu uninstall I've got this info:
$ npm uninstall gatsby-cli
npm WARN [email protected] No description
npm WARN [email protected] No repository field.

audited 1 package in 1.448s

1 package is looking for funding
run npm fund for details

found 0 vulnerabilities

and after that when I try to install
$ npm install -g gatsby-cli
npm WARN deprecated [email protected]: core-js@<3 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js@3.
C:\Program Files\Git\user\local\gatsby -> C:Program FilesGituserlocalnode_modulesgatsby-clicli.js

[email protected] postinstall C:Program FilesGituserlocalnode_modulesgatsby-cli
node scripts/postinstall.js

Success!

Welcome to the Gatsby CLI! Please visit https://www.gatsbyjs.org/docs/gatsby-cli/ for more information.

npm WARN [email protected] requires a peer of acorn@^6.0.0 but none is installed. You must install peer dependencies yourself.

a

yup this works as of July 2020.

https://docs.npmjs.com/try-the-latest-stable-version-of-npm
hint is there on how to make gatsby work on windows

  1. npm config get prefix -g enter this on prompt and see where it is pointing . this where gatsby gets installed when we do npm install -g gatsby-cli
  2. if gatsby is installing on different location nodejs path , simply copy gatsby files and folders and move them to nodejs folder it works

I got something like this:
$ npm install npm@latest
npm WARN saveError ENOENT: no such file or directory, open 'C:Program Filesnodejspackage.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open 'C:Program Filesnodejspackage.json'
npm WARN nodejs No description
npm WARN nodejs No repository field.
npm WARN nodejs No README data
npm WARN nodejs No license field.

  • [email protected]
    added 16 packages from 2 contributors, removed 17 packages, updated 19 packages and audited 434 packages in 11.243s

2 packages are looking for funding
run npm fund for details

found 0 vulnerabilities

and the path is:
$ npm config get prefix -g
C:Program FilesGituserlocal

When I try to use this command: npm config set prefix "${APPDATA}/npm" -g
it' changes nothing.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ferMartz picture ferMartz  路  3Comments

totsteps picture totsteps  路  3Comments

theduke picture theduke  路  3Comments

brandonmp picture brandonmp  路  3Comments

Oppenheimer1 picture Oppenheimer1  路  3Comments