![](/img/trans.png)
[英]"'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.