簡體   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

當我嘗試使用 npm 和 yarn 創建反應項目時,它顯示以下錯誤:

我嘗試通過運行 npm install -g create-react-app@latest 重新安裝 node 並確保它是最新的,以及 create-react-app。 我還刪除了 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.

我認為問題是由於操作系統問題將我的 Windows 10 恢復到以前的狀態,因為在恢復它之前,當我運行 create-react-app 時,它可以正常工作。

create-react-app --version 3.1.1

節點 -v v10.16.3

npm -v 6.9.0

SO Windows 10 教育版

使用npm init安裝 package.json (按回車直到安裝)
之后使用npm i react-scripts安裝npm i react-scripts
然后你可以使用npx create-react-app your-app安裝 react。
將目錄更改為“您的應用程序”
再次npm i react-scripts ,它應該可以工作。

希望我沒有錯過任何一步,如果有效,請告訴我:)

只需在 git bash 上運行此代碼:

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

也許它會幫助別人。

如果您的路徑中有一些無效字符,則在使用 create-react-app 后可能會發生此錯誤。

從您的路徑中刪除像&這樣的字符。

例如,從這里更改:

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

對此:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM