npm / cli

the package manager for JavaScript
https://docs.npmjs.com/cli/
Other
8.43k stars 3.13k forks source link

Creating a new react app with create-react-app results in Error: Cannot find module 'has-flag' #6097

Closed grantspilsbury closed 5 months ago

grantspilsbury commented 1 year ago

Is there an existing issue for this?

This issue exists in the latest npm version

Current Behavior

I am trying to create a new react app. In an empty folder I run npx create-react-app my-app

Which results in the following error:

node:internal/modules/cjs/loader:1042
  throw err;
  ^

Error: Cannot find module 'has-flag'
Require stack:
- /Users/gs/.npm/_npx/c67e74de0542c87c/node_modules/chalk/node_modules/supports-color/index.js
- /Users/gs/.npm/_npx/c67e74de0542c87c/node_modules/chalk/source/index.js
- /Users/gs/.npm/_npx/c67e74de0542c87c/node_modules/create-react-app/createReactApp.js
- /Users/gs/.npm/_npx/c67e74de0542c87c/node_modules/create-react-app/index.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1039:15)
    at Module._load (node:internal/modules/cjs/loader:885:27)
    at Module.require (node:internal/modules/cjs/loader:1105:19)
    at require (node:internal/modules/cjs/helpers:103:18)
    at Object.<anonymous> (/Users/gs/.npm/_npx/c67e74de0542c87c/node_modules/chalk/node_modules/supports-color/index.js:4:17)
    at Module._compile (node:internal/modules/cjs/loader:1218:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1272:10)
    at Module.load (node:internal/modules/cjs/loader:1081:32)
    at Module._load (node:internal/modules/cjs/loader:922:12)
    at Module.require (node:internal/modules/cjs/loader:1105:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/gs/.npm/_npx/c67e74de0542c87c/node_modules/chalk/node_modules/supports-color/index.js',
    '/Users/gs/.npm/_npx/c67e74de0542c87c/node_modules/chalk/source/index.js',
    '/Users/gs/.npm/_npx/c67e74de0542c87c/node_modules/create-react-app/createReactApp.js',
    '/Users/gs/.npm/_npx/c67e74de0542c87c/node_modules/create-react-app/index.js'
  ]
}

Node.js v18.13.0

Expected Behavior

No response

Steps To Reproduce

npm: 9.4.0 Node.js: v18.13.0 in an empty folder run npx create-react-app my-app

Environment

registry=https://registry.npmjs.org/

;;;; ; all available options shown below with default values ;;;;

; _auth=null ; access=null ; all=false ; allow-same-version=false ; also=null ; audit=true ; audit-level=null ; auth-type=web ; before=null ; bin-links=true ; browser=null ; ca=null ; cache=~/.npm ; cache-max=null ; cache-min=0 ; cafile=null ; call= ; cert=null ; ci-name=null ; cidr=null ; color=true ; commit-hooks=true ; depth=null ; description=true ; dev=false ; ; diff-ignore-all-space=false ; diff-name-only=false ; diff-no-prefix=false ; diff-dst-prefix=b/ ; diff-src-prefix=a/ ; diff-text=false ; diff-unified=3 ; dry-run=false ; editor=nano ; engine-strict=false ; fetch-retries=2 ; fetch-retry-factor=10 ; fetch-retry-maxtimeout=60000 ; fetch-retry-mintimeout=10000 ; fetch-timeout=300000 ; force=false ; foreground-scripts=false ; format-package-lock=true ; fund=true ; git=git ; git-tag-version=true ; global=false ; globalconfig= ; global-style=false ; heading=npm ; https-proxy=null ; if-present=false ; ignore-scripts=false ; ; include-staged=false ; include-workspace-root=false ; init-author-email= ; init-author-name= ; init-author-url= ; init-license=ISC ; init-module=~/.npm-init.js ; init-version=1.0.0 ; init.author.email= ; init.author.name= ; init.author.url= ; init.license=ISC ; init.module=~/.npm-init.js ; init.version=1.0.0 ; install-links=true ; install-strategy=hoisted ; json=false ; key=null ; legacy-bundling=false ; legacy-peer-deps=false ; link=false ; local-address=null ; location=user ; lockfile-version=null ; loglevel=notice ; logs-dir=null ; logs-max=10 ; long=false ; maxsockets=15 ; message=%s ; node-options=null ; noproxy= ; offline=false ; ; omit-lockfile-registry-resolved=false ; only=null ; optional=null ; otp=null ; ; package-lock=true ; package-lock-only=false ; pack-destination=. ; parseable=false ; prefer-offline=false ; prefer-online=false ; prefix= ; preid= ; production=null ; progress=true ; proxy=null ; read-only=false ; rebuild-bundle=true ; registry=https://registry.npmjs.org/ ; replace-registry-host=npmjs ; save=true ; save-bundle=false ; save-dev=false ; save-exact=false ; save-optional=false ; save-peer=false ; save-prefix=^ ; save-prod=false ; scope= ; script-shell=null ; searchexclude= ; searchlimit=20 ; searchopts= ; searchstaleness=900 ; shell=/bin/zsh ; shrinkwrap=true ; sign-git-commit=false ; sign-git-tag=false ; strict-peer-deps=false ; strict-ssl=true ; tag=latest ; tag-version-prefix=v ; timing=false ; tmp=/var/folders/pn/b7vg58ts5_b9xc3b7zvvpn780000gr/T ; umask=0 ; unicode=true ; update-notifier=true ; usage=false ; user-agent=npm/{npm-version} node/{node-version} {platform} {arch} workspaces/{workspaces} {ci} ; userconfig=~/.npmrc ; version=false ; versions=false ; viewer=man ; which=null ; ; workspaces=null ; workspaces-update=true ; yes=null

fritzy commented 1 year ago

I'm not able to reproduce this in npm@9.5.1. Can you include your computed configuration with npm config list?

milaninfy commented 5 months ago

Closing due to age. If this is still a problem please feel free to reopen this issue, or create a new issue w/ steps to reproduce.