[英]"'npm' is not recognized as an internal or external command" on create-react-app
[英]'serve' is not recognized as an internal or external command to run react app
我知道運行npx serve -s build
應該可以。 我和你有同樣的問題。 npx 命令對我有用。 如果您有 npx 問題,請檢查您的 nodejs 版本。 我正在運行 10.16.2(以便我們在同一頁面上)。 https://www.npmjs.com/package/serve
您的其余問題與您的其余設置有關。 我沒有自己的 server.js 文件(有一些 node_module server.js 文件,是這個意思嗎)?
據我了解 create-react-app, npm run start
將允許您在本地運行您的應用程序。 我不需要serve -s build
。
我使用了 amplify create react 應用程序。 對於 amplify 應用程序,我只需運行amplify publish
,我的應用程序的構建目錄就會發送到 S3 存儲桶。 如果你沒有那個配置,並且你想要快速而骯臟的答案......只需在你的反應應用程序中獲取你的構建目錄的內容並將這些文件放在你的網絡服務器上。 這應該讓你完成了 90%(注意呈現的默認頁面)。
服務 React 文件
基本示例:-
const express = require('express');
const path = require('path');
const app = express();
app.use(express.static(path.join(__dirname, 'build')));
app.get('/', function(req, res) {
res.sendFile(path.join(__dirname, 'build', 'index.html'));
});
app.listen(9000);
對於域中的基本路徑,提供從構建過程中獲取的 index.html。
如果您需要更多信息:- https://create-react-app.dev/docs/deployment
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.