我在尝试创建反应应用程序时遇到问题 - 错误:找不到模块'./gitignore'



我是windows用户,安装了git、node和yarn。这是创建我的React应用程序所必需的,我收到了一个中止安装的错误。你能告诉我如何解决吗,因为我已经安装和卸载了node和git,我认为这两个中的哪一个会导致问题或文件夹丢失?

PS C:React> npx create-react-app my-app
Creating a new React app in C:Reactmy-app.
Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts with cra-template...
yarn add v1.22.4
[1/4] Resolving packages...
[2/4] Fetching packages...
info fsevents@1.2.12: The platform "win32" is incompatible with this module.
info "fsevents@1.2.12" is an optional dependency and failed compatibility check. Excluding it from installation.
info fsevents@2.1.2: The platform "win32" is incompatible with this module.
info "fsevents@2.1.2" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
warning "react-scripts > @typescript-eslint/eslint-plugin > tsutils@3.17.1" has unmet peer dependency "typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta".
[4/4] Building fresh packages...
success Saved lockfile.
success Saved 13 new dependencies.
info Direct dependencies
├─ cra-template@1.0.3
├─ react-dom@16.13.1
├─ react-scripts@3.4.1
└─ react@16.13.1
info All dependencies
├─ @babel/plugin-transform-flow-strip-types@7.9.0
├─ @babel/plugin-transform-runtime@7.9.0
├─ @babel/plugin-transform-typescript@7.9.4
├─ @babel/preset-typescript@7.9.0
├─ babel-preset-react-app@9.1.2
├─ cra-template@1.0.3
├─ eslint-config-react-app@5.2.1
├─ react-dev-utils@10.2.1
├─ react-dom@16.13.1
├─ react-error-overlay@6.0.7
├─ react-scripts@3.4.1
├─ react@16.13.1
└─ scheduler@0.19.1
Done in 34.13s.
internal/modules/cjs/loader.js:983
throw err;
^
Error: Cannot find module './gitignore'
Require stack:
- C:Reactmy-appnode_modulesglobbyindex.js
- C:Reactmy-appnode_modulesreact-dev-utilsglobby.js
- C:Reactmy-appnode_modulesreact-scriptsscriptsutilsverifyTypeScriptSetup.js
- C:Reactmy-appnode_modulesreact-scriptsscriptsinit.js
- C:Reactmy-app[eval]
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:980:15)
at Function.Module._load (internal/modules/cjs/loader.js:862:27)
at Module.require (internal/modules/cjs/loader.js:1042:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object.<anonymous> (C:Reactmy-appnode_modulesglobbyindex.js:6:19)
at Module._compile (internal/modules/cjs/loader.js:1156:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
at Module.load (internal/modules/cjs/loader.js:1000:32)
at Function.Module._load (internal/modules/cjs/loader.js:899:14)
at Module.require (internal/modules/cjs/loader.js:1042:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'C:\React\my-app\node_modules\globby\index.js',
'C:\React\my-app\node_modules\react-dev-utils\globby.js',
'C:\React\my-app\node_modules\react-scripts\scripts\utils\verifyTypeScriptSetup.js',
'C:\React\my-app\node_modules\react-scripts\scripts\init.js',
'C:\React\my-app\[eval]'
]
}
Aborting installation.
node  has failed.
Deleting generated file... node_modules
Deleting generated file... package.json
Deleting generated file... yarn.lock
Deleting my-app/ from C:React
Done.
PS C:React>

检查您是否无意将gitignore导入项目中的某个位置。在所有代码文件中搜索它。

你可能想试试这篇文章中的建议:React:创建React应用程序失败并出现错误"找不到模块';lodash'&";。

也就是说,运行:

npm cache clean --force 
npm i 
npm i -g create-react-app 

然后重试此命令:

npx create-react-app my-app

清除纱线缓存在终端中键入以下命令:

yarn cache clean

相关内容

最新更新