[英]'npm run build' gives no error but 'npm start' gives error
我之前在完全相同的代碼上執行npm start
沒有任何錯誤。 自從上次我沒有任何錯誤地執行它以來,我沒有對文件進行任何更改。 但就在一天后,同樣的代碼突然報錯:
> client@0.1.0 start
> react-scripts start
Cannot use import statement outside a module
我不明白為什么會這樣。 但是, npm run build
編譯沒有任何錯誤並正確生成構建。 所以我不認為這是代碼的問題。
進一步,我再次運行npm install
,發現有一些漏洞:
added 684 packages, removed 193 packages, changed 411 packages, and audited 1873 packages in 2m
153 packages are looking for funding
run `npm fund` for details
32 vulnerabilities (19 moderate, 12 high, 1 critical)
To address issues that do not require attention, run:
npm audit fix
To address all issues (including breaking changes), run:
npm audit fix --force
Run `npm audit` for details.
因此,按照我使用npm audit fix --force
的說明,我看到它已將react-scripts
更新到版本 5.0.0。 這突然解決了之前的錯誤,之后編譯的代碼沒有錯誤,但是,現在我遇到了另一個問題。
在訪問localhost:3000
時,它顯示localhost refused to connect
,即使我的終端顯示代碼已成功編譯。
這是我遇到錯誤的項目: https://github.com/DevRish/martcart 。
我還打開了一個關於此的問題: https://github.com/DevRish/martcart/issues/1
我對這里的兩件事感到困惑。 首先, react-scripts
4.0.3版本,為什么build編譯沒有錯誤,開發環境卻報錯? 其次,即使react-scripts
5.0.0 版本編譯成功,為什么localhost:3000 顯示'refused to connect'?
更新:刪除 setupProxy.js 文件后,它工作正常。
我在package.json文件中添加了proxy屬性來實現代理功能。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.