简体   繁体   English

create-react-app 返回错误:执行时找不到模块“react-scripts/scripts/init.js”

[英]create-react-app returns an Error: Cannot find module 'react-scripts/scripts/init.js' when executed

when I try to create a react project with both npm and yarn, it shows me the following error:当我尝试使用 npm 和 yarn 创建反应项目时,它显示以下错误:

I tried to reinstall node and make sure it was up to date, as well as create-react-app by running npm install -g create-react-app@latest.我尝试通过运行 npm install -g create-react-app@latest 重新安装 node 并确保它是最新的,以及 create-react-app。 I also removed the npm and npm-cache folders and the environment variable, but nothing works for me and I keep getting the same error.我还删除了 npm 和 npm-cache 文件夹和环境变量,但对我没有任何作用,而且我不断收到相同的错误。

internal/modules/cjs/loader.js:638
    throw err;
    ^

Error: Cannot find module 'react-scripts/scripts/init.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at [eval]:2:20
    at Script.runInThisContext (vm.js:122:20)
    at Object.runInThisContext (vm.js:329:38)
    at Object.<anonymous> ([eval]-wrapper:6:22)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at evalScript (internal/bootstrap/node.js:589:27)

Aborting installation.
  node  has failed.

Deleting generated file... node_modules
Deleting generated file... package.json
Deleting generated file... yarn.lock
Deleting test/ from C:\Users\Esper\projects
Done.

I think the problem arose from restoring my windows 10 to a previous state due to operating system problems, because before restoring it, when I run create-react-app it worked correctly.我认为问题是由于操作系统问题将我的 Windows 10 恢复到以前的状态,因为在恢复它之前,当我运行 create-react-app 时,它可以正常工作。

create-react-app --version 3.1.1 create-react-app --version 3.1.1

node -v v10.16.3节点 -v v10.16.3

npm -v 6.9.0 npm -v 6.9.0

SO Windows 10 Education SO Windows 10 教育版

Install a package.json with npm init (press enter till is installed)使用npm init安装 package.json (按回车直到安装)
After that install react-scripts with npm i react-scripts ,之后使用npm i react-scripts安装npm i react-scripts
Then you can install react with npx create-react-app your-app .然后你可以使用npx create-react-app your-app安装 react。
Change the directory to "your-app"将目录更改为“您的应用程序”
Run again npm i react-scripts and it should work.再次npm i react-scripts ,它应该可以工作。

Hope I did not missed a step, let me know if works :)希望我没有错过任何一步,如果有效,请告诉我:)

Just run this code on git bash:只需在 git bash 上运行此代码:

npm install
npm install react-scripts
npx create-react-app your-app-name

Maybe it will help somebody else.也许它会帮助别人。

This error can happen after you use create-react-app in case you have some invalid character in your path.如果您的路径中有一些无效字符,则在使用 create-react-app 后可能会发生此错误。

Remove charecteres like & from your path.从您的路径中删除像&这样的字符。

For example, change from this:例如,从这里更改:

C:\Users\...\Documents\Section 3 Components & Start\my-app

To this:对此:

C:\Users\...\Documents\Section 3 Components Start\my-app

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 create-react-app 后无法启动项目:错误:找不到模块“C:\Users\pcname\Documents\react-scripts\bin\react-scripts.js” - Unable to start project after create-react-app: Error: Cannot find module 'C:\Users\pcname\Documents\react-scripts\bin\react-scripts.js' UnhandledPromiseRejectionWarning:错误:找不到模块“/MyProject/node_modules/react-native-scripts/build/scripts/init.js” - UnhandledPromiseRejectionWarning: Error: Cannot find module '/MyProject/node_modules/react-native-scripts/build/scripts/init.js' react-scripts:在ubuntu的create-react-app项目上找不到? - react-scripts: not found on create-react-app project on ubuntu? 错误:找不到模块“/app/react-web/react-scripts” - Error: Cannot find module '/app/react-web/react-scripts' 创建一个带有快速“react-scripts”错误的 React 应用程序 - Create a React app with express, 'react-scripts' error create-react-app + npm start - &#39;react-scripts&#39; 不被识别为内部或外部命令 - create-react-app + npm start - 'react-scripts' is not recognized as an internal or external command Create-react-app返回“无法找到模块&#39;rxjs&#39;” - Create-react-app returns “Cannot find module 'rxjs'” 使用 Moment JS 创建 React-App:找不到模块“./locale” - Create-React-App with Moment JS: Cannot find module “./locale” create-react-app 命令卡在使用 cra-template 安装 react react-dom react-scripts - create-react-app command stuck on installing react react-dom react-scripts with cra-template 如何在没有 react-scripts 的情况下运行 React.js 应用程序? - How to run React.js app without react-scripts?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM