reactjs - 将全栈应用程序部署到 Google App Engine 并出现错误 webpack:未找到
问题描述
每个人。我尝试从https://github.com/crsandeep/simple-react-full-stack部署 Reack 全栈应用程序, 但它不起作用。我阅读了太多关于将 react 部署到 gcloud 的帖子,但是有简单的应用程序而不是全栈应用程序。
我的 packege.json,我从 git 拿来的
{
"name": "simple-react-full-stack",
"version": "1.0.0",
"description": "Boilerplate to build a full stack web application using React, Node.js, Express and Webpack.",
"main": "src/server/index.js",
"scripts": {
"build": "webpack --mode production",
"start": "npm run build && node src/server/index.js",
"client": "webpack-dev-server --mode development --devtool inline-source-map --hot",
"server": "nodemon src/server/index.js",
"dev": "concurrently \"npm run server\" \"npm run client\""
},
"author": "Sandeep Raveesh",
"license": "ISC",
"dependencies": {
"babel-polyfill": "^6.26.0",
"express": "^4.16.3",
"react": "^16.5.2",
"react-dom": "^16.5.2"
},
"devDependencies": {
"@babel/core": "^7.0.0",
"@babel/plugin-proposal-class-properties": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@babel/preset-react": "^7.0.0",
"babel-eslint": "^10.0.0",
"babel-loader": "^8.0.0",
"clean-webpack-plugin": "^1.0.0",
"concurrently": "^4.0.0",
"css-loader": "^2.0.0",
"eslint": "^5.0.0",
"eslint-config-airbnb": "^17.0.0",
"eslint-plugin-import": "^2.11.0",
"eslint-plugin-jsx-a11y": "^6.0.3",
"eslint-plugin-react": "^7.7.0",
"file-loader": "^3.0.0",
"html-webpack-plugin": "^3.2.0",
"nodemon": "^1.17.3",
"style-loader": "^0.23.0",
"url-loader": "^1.0.1",
"webpack": "^4.5.0",
"webpack-cli": "^3.0.8",
"webpack-dev-server": "^3.1.3"
}
}
我的 app.yaml 我从谷歌拿的
env: flex
runtime: nodejs
我在终端运行
gcloud beta app deploy
我有错误
Updating service [default] (this may take several minutes)...failed.
ERROR: (gcloud.beta.app.deploy) Error Response: [9]
Application startup error:
> simple-react-full-stack@1.0.0 prestart /app
> npm run bundle
> simple-react-full-stack@1.0.0 bundle /app
> webpack --config webpack.config.js
sh: 1: webpack: not found
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! simple-react-full-stack@1.0.0 bundle: `webpack --config webpack.config.js`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the simple-react-full-stack@1.0.0 bundle script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2019-12-04T18_45_03_238Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! simple-react-full-stack@1.0.0 prestart: `npm run bundle`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the simple-react-full-stack@1.0.0 prestart script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2019-12-04T18_45_03_252Z-debug.log
我不明白它需要什么,我尝试添加“npm install”,但它也不起作用。怎么修?
解决方案
这是您可以遵循的社区教程,首先按照说明进行所有操作,然后开始进行所需的编辑。
Please make sure you are following the steps of "Preparing the app" section, as it seems like you are missing on of the mentioned steps.
npm init
npm install --save webpack express pug
As well as modifying package.json to include:
"scripts": {
"bundle": "webpack --config webpack.config.js",
"prestart": "npm run bundle"
}
Also note that:
Webpack must be listed in the dependencies of the package.json file, as by default devDependencies are not installed when the app is deployed to Google App Engine.
Also keep in mind that gcloud beta app deploy
is still in BETA and may have changes without notice. So for what you are trying to achieve there is no need for using beta. Instead simply use gcloud app deploy
.
推荐阅读
- ios - 执行人脸识别时出现opencv灯问题
- javascript - 如何使用函数添加 api 键值,可能是语法错误
- php - 如何使用 php artisan serve 设置域名
- java - 在 Spring Boot Rest Controller 中解析 Json 数组初始化单个对象
- c# - MVC Core 将 ViewModel 绑定到模型
- java - 打印网格时Java索引越界异常
- reporting-services - 在终端 PC 上通过最终用户登录访问报表管理器时出现空白页
- pyspark - WARN TaskMemoryManager:302 - 分配页面失败(16777216 字节),再试一次
- git - 如何在 Git 中以 root 身份克隆特定的子目录?
- azure-cosmosdb - 在 cosmos db 中转换 JSON 结构