主頁 > 企業開發 > GCPAppEngine和CloudBuild:找不到模塊“/workspace/server.js”

GCPAppEngine和CloudBuild:找不到模塊“/workspace/server.js”

2021-12-03 08:24:52 企業開發

TLDR:對不起,這是歷史上最長的問題,但我希望這對遇到類似問題的任何用戶來說都是全面的。我的應用程式從云外殼成功部署到我的域;但是,當我嘗試云構建時,我得到 Cannot find module '/workspace/server.js' 錯誤可能與我在 app.yaml 中的構建處理程式有關,或者與我的 cloudbuild.yaml 有關。

解決方案:在 app.yaml 標準中使用正確的處理程式并正確設定您的 cloudbuild.yaml

我在同時使用 App Engine 和 Cloud Build 時遇到問題。我正在使用 Cloud Build 通過我的 Github 存盤庫設定 CICD。我認為問題是由于我沒有將生產版本部署到應用程式引擎。我能夠成功地手動部署(開發版):

gcloud app deploy

現在,我的 Cloud Build 遇到了問題。特別是,我正在嘗試運行 flex 環境,但我一直在“package.json”的“scripts”部分中“既沒有找到“start”,也沒有找到“server.js”檔案。” 但是我的 package.json 有啟動腳本?

我還嘗試了標準環境而不是 flex,但我無法弄清楚處理程式。我嘗試了幾十個例子。我已經包含了標準環境 app.yaml 以便您可以看到它。

這是我的 package.json:

{
  "name": "flier-mapper",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@firebase/storage": "^0.8.4",
    "@parcel/transformer-sass": "^2.0.0",
    "@react-google-maps/api": "^2.7.0",
    "@testing-library/jest-dom": "^5.11.4",
    "@testing-library/react": "^11.1.0",
    "@testing-library/user-event": "^12.1.10",
    "bootstrap": "^5.1.3",
    "cors": "^2.8.5",
    "emailjs-com": "^3.2.0",
    "firebase": "^9.2.0",
    "firebase-admin": "^10.0.0",
    "firebase-functions": "^3.16.0",
    "react": "^17.0.2",
    "react-bootstrap": "^2.0.2",
    "react-dom": "^17.0.2",
    "react-ga": "^3.3.0",
    "react-helmet": "^6.1.0",
    "react-icons": "^4.3.1",
    "react-pricing-table": "^0.3.0",
    "react-router-dom": "^5.3.0",
    "react-scripts": "4.0.3",
    "react-tabs": "^3.2.3",
    "stripe": "^8.188.0",
    "web-vitals": "^1.0.1"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

這是我的 cloudbuild.yaml。我也嘗試洗掉 dir 行:

steps:

- name: "gcr.io/cloud-builders/npm"
  dir: 'frontend'
  args: ['install']
  timeout: "5m"

- name: "gcr.io/cloud-builders/npm"
  dir: 'frontend'
  args: ["run", "build"]
  timeout: "5m"

- name: "gcr.io/cloud-builders/gcloud"
  entrypoint: bash
  args: 
    - "-c"
    - |
        cp app.yaml ./build
        cd build
        gcloud app deploy
  timeout: "1600s"

timeout: 60m

這是我的 flex app.yaml:

runtime: nodejs
env: flex

# This sample incurs costs to run on the App Engine flexible environment.
  # The settings below are to reduce costs during testing and are not appropriate
# for production use. For more information, see:
# https://cloud.google.com/appengine/docs/flexible/nodejs/configuring-your-app-with-app-yaml
manual_scaling:
  instances: 1
resources:
  cpu: 1
  memory_gb: 0.5
  disk_size_gb: 10

這是我在標準環境中嘗試過的眾多處理程式之一:

runtime: nodejs14

# This sample incurs costs to run on the App Engine flexible environment.
# The settings below are to reduce costs during testing and are not appropriate
# for production use. For more information, see:
# https://cloud.google.com/appengine/docs/flexible/nodejs/configuring-your-app-with-app-yaml
manual_scaling:
  instances: 1

handlers:
  # Serve all static files with url ending with a file extension
  - url: /(.*\.. )$
    static_files: build/\1
    upload: build/(.*\.. )$
  # Catch all handler to index.html
  - url: /.*
    static_files: build/index.html
    upload: build/index.html

  - url: /.*
    secure: always
    redirect_http_response_code: 301
    script: auto

編輯

所以,我讓它在標準環境中運行,這對 https 請求很有用。這是我開始作業的 app.yaml:

runtime: nodejs14

# This sample incurs costs to run on the App Engine flexible environment.
# The settings below are to reduce costs during testing and are not appropriate
# for production use. For more information, see:
# https://cloud.google.com/appengine/docs/flexible/nodejs/configuring-your-app-with-app-yaml
manual_scaling:
  instances: 2

handlers:

- url: /.*
  secure: always
  redirect_http_response_code: 301
  script: auto

但是,現在我的問題是:

Error: Cannot find module '/workspace/server.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:889:15)
    at Function.Module._load (internal/modules/cjs/loader.js:745:27)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
    at internal/main/run_main_module.js:17:47 {

Which is essentially the same issue as above.

GCP App Engine 和 Cloud Build:找不到模塊“/workspace/server.js”

EDIT 2

I'm wondering if it is because now that I am running a production build I need to add the correct handlers. But as mentioned above, I have tried dozens of combinations of various answers on the internet to no avail.

Here's another standard app.yaml I tried:

runtime: nodejs16

# This sample incurs costs to run on the App Engine flexible environment.
# The settings below are to reduce costs during testing and are not appropriate
# for production use. For more information, see:
# https://cloud.google.com/appengine/docs/flexible/nodejs/configuring-your-app-with-app-yaml
manual_scaling:
  instances: 2

handlers:
  - url: /.*
    secure: always
    redirect_http_response_code: 301
    script: auto

  - url: /
    static_files: build/index.html
    upload: build/index.html

  - url: /
    static_dir: build

Is it something to do with one of my packages? If so, which one? There aren't any specials ones that I know of...

I also added this to my package.json, but it didn't do anything either:

"start": "PORT=8080 react-scripts start",

EDIT 3 I have tried these posts: Error: Cannot find module '/workspace/server.js' could not find module workspace/server.js Error: Cannot find module '/workspace/server.js' upon node js deploy on google app engine https://medium.com/@calebmackdaven/so-you-want-to-start-using-google-cloud-ce9054e84fa8

This app.yaml built on cloud build; however, I now get a new error "The requested URL / was not found on this server.":

runtime: nodejs16

# This sample incurs costs to run on the App Engine flexible environment.
# The settings below are to reduce costs during testing and are not appropriate
# for production use. For more information, see:
# https://cloud.google.com/appengine/docs/flexible/nodejs/configuring-your-app-with-app-yaml
manual_scaling:
  instances: 2

handlers:
  - url: /static/js/(.*)
    static_files: build/static/js/\1
    upload: build/static/js/(.*)
  - url: /static/css/(.*)
    static_files: build/static/css/\1
    upload: build/static/css/(.*)
  - url: /static/media/(.*)
    static_files: build/static/media/\1
    upload: build/static/media/(.*)
  - url: /(.*\.(json|ico))$
    static_files: build/\1
    upload: build/.*\.(json|ico)$
  - url: /
    static_files: build/index.html
    upload: build/index.html
  - url: /.*
    static_files: build/index.html
    upload: build/index.html
  - url: /.*
    secure: always
    redirect_http_response_code: 301
    script: auto

My logs say:

Static file referenced by handler not found: build/index.html

EDIT 4 I tried a different cloudbuild.yaml:

steps:

- name: node
  entrypoint: npm
  args: ['install']

- name: node
  entrypoint: npm
  args: ['run', 'build']

- name: 'bash'
  args: ['gcloud app deploy']

However, now the error I get in my npm run build stage is :

Error message "error:0308010C:digital envelope routines::unsupported"

I checked out this answer, so I tried a different node version 14 and still got the same issue. I tried the following, but got the same error:

"start": "react-scripts --openssl-legacy-provider start"

Here's my error:

Step #1: Error: error:0308010C:digital envelope routines::unsupported
Step #1:     at new Hash (node:internal/crypto/hash:67:19)
Step #1:     at Object.createHash (node:crypto:130:10)
Step #1:     at module.exports (/workspace/node_modules/webpack/lib/util/createHash.js:135:53)
Step #1:     at NormalModule._initBuildHash (/workspace/node_modules/webpack/lib/NormalModule.js:417:16)
Step #1:     at /workspace/node_modules/webpack/lib/NormalModule.js:452:10
Step #1:     at /workspace/node_modules/webpack/lib/NormalModule.js:323:13
Step #1:     at /workspace/node_modules/loader-runner/lib/LoaderRunner.js:367:11
Step #1:     at /workspace/node_modules/loader-runner/lib/LoaderRunner.js:233:18
Step #1:     at context.callback (/workspace/node_modules/loader-runner/lib/LoaderRunner.js:111:13)
Step #1:     at /workspace/node_modules/babel-loader/lib/index.js:59:103 {
Step #1:   opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
Step #1:   library: 'digital envelope routines',
Step #1:   reason: 'unsupported',
Step #1:   code: 'ERR_OSSL_EVP_UNSUPPORTED'
Step #1: }
Step #1: 
Step #1: Node.js v17.1.0
Finished Step #1
ERROR
ERROR: build step 1 "node" failed: step exited with non-zero status: 1

Why is it attempting to use Node.js v17.1.0 when I specified v16 in the app.yaml?

EDIT 5

I tried specifying Node v16.13.0:

steps:
- name: node: "16.13.0"
  entrypoint: npm
  args: ['install']

- name: node: "16.13.0"
  entrypoint: npm
  args: ['run', 'build']

- name: "gcr.io/cloud-builders/gcloud"
  entrypoint: bash
  args: [gcloud app deploy]

However, it didn't build at all:

Your build failed to run: failed unmarshalling build config cloudbuild.yaml: yaml: line 2: mapping values are not allowed in this context

So I tried adding a substitution:

--- 
steps: 
  - 
    args: 
      - install
    entrypoint: npm
    name: "node= $_NODE_VERSION"
  - 
    args: 
      - run
      - build
    entrypoint: npm
    name: "node= $_NODE_VERSION"
  - 
    args: 
      - "gcloud app deploy"
    entrypoint: bash
    name: gcr.io/cloud-builders/gcloud
substitutions: 
  $_NODE_VERSION: v16.13.0

But I got:

Your build failed to run: generic::invalid_argument: invalid build: invalid build step name "node= ": could not parse reference: node=

And if I try node: "16.13.0", the error is similar:

Your build failed to run: failed unmarshalling build config cloudbuild.yaml: yaml: line 2: mapping values are not allowed in this context

Okay, that error was just due to spacing. I tried updating my cloudbuild.yaml as follows:

steps:
- name: node:16.13.0
  entrypoint: npm
  args: ['install']

- name: node:16.13.0
  entrypoint: npm
  args: ['run', 'build']

- name: "gcr.io/cloud-builders/gcloud"
  entrypoint: bash
  args: [gcloud app deploy]

Now I am able to build. However, now I get an issue with the gcloud command:

Step #2: bash: gcloud app deploy: No such file or directory

EDIT 6

I'm going in circles. My new error is the original one:

Error: Not Found
The requested URL / was not found on this server.

But at least I got the cloud build to build. So it must be my app.yaml or cloudbuild.yaml.

steps:
- name: node:16.13.0
  entrypoint: npm
  args: ['install']

- name: node:16.13.0
  entrypoint: npm
  args: ['run', 'build']

- name: "gcr.io/cloud-builders/gcloud"
  entrypoint: bash
  args: 
    - "-c"
    - |
        cp app.yaml ./build
        cd build
        gcloud app deploy
Step #2: bash: gcloud app deploy: No such file or directory

Solution I finally got it working! I was changing directory to build, but shouldn't have been. So here are my working cloudbuild.yaml and app.yaml files:

cloudbuild.yaml

steps:
- name: node:16.13.0
  entrypoint: npm
  args: ['install']

- name: node:16.13.0
  entrypoint: npm
  args: ['run', 'build']

- name: "gcr.io/cloud-builders/gcloud"
  entrypoint: bash
  args: 
    - "-c"
    - |
        cp app.yaml ./build
        gcloud app deploy

app.yaml

--- 
handlers: 
  - 
    secure: always
    static_dir: build/static
    url: /static
  - 
    secure: always
    static_files: build/\1
    upload: build/.*\.(json|ico|js)$
    url: /(.*\.(json|ico|js))$
  - 
    secure: always
    static_files: build/index.html
    upload: build/index.html
    url: .*
manual_scaling: 
  instances: 1
runtime: nodejs16

uj5u.com熱心網友回復:

解決方案 我終于讓它作業了!我正在更改目錄以進行構建,但不應該如此。所以這是我的作業 cloudbuild.yaml 和 app.yaml 檔案:

云構建.yaml

steps:
- name: node:16.13.0
  entrypoint: npm
  args: ['install']

- name: node:16.13.0
  entrypoint: npm
  args: ['run', 'build']

- name: "gcr.io/cloud-builders/gcloud"
  entrypoint: bash
  args: 
    - "-c"
    - |
        cp app.yaml ./build #not sure if this is necessary
        gcloud app deploy

應用程式.yaml

--- 
handlers: 
  - 
    secure: always
    static_dir: build/static
    url: /static
  - 
    secure: always
    static_files: build/\1
    upload: build/.*\.(json|ico|js)$
    url: /(.*\.(json|ico|js))$
  - 
    secure: always
    static_files: build/index.html
    upload: build/index.html
    url: .*
manual_scaling: 
  instances: 1
runtime: nodejs16

轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/372077.html

標籤:reactjs google-app-engine google-cloud-platform google-cloud-build app.yaml

上一篇:運行多年的舊應用程式中的404錯誤

下一篇:Certbot:嘗試為GoogleCloudPlatform的AppEngine上的應用程式創建通配符證書時出現“某些挑戰失敗”

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • IEEE1588PTP在數字化變電站時鐘同步方面的應用

    IEEE1588ptp在數字化變電站時鐘同步方面的應用 京準電子科技官微——ahjzsz 一、電力系統時間同步基本概況 隨著對IEC 61850標準研究的不斷深入,國內外學者提出基于IEC61850通信標準體系建設數字化變電站的發展思路。數字化變電站與常規變電站的顯著區別在于程序層傳統的電流/電壓互 ......

    uj5u.com 2020-09-10 03:51:52 more
  • HTTP request smuggling CL.TE

    CL.TE 簡介 前端通過Content-Length處理請求,通過反向代理或者負載均衡將請求轉發到后端,后端Transfer-Encoding優先級較高,以TE處理請求造成安全問題。 檢測 發送如下資料包 POST / HTTP/1.1 Host: ac391f7e1e9af821806e890 ......

    uj5u.com 2020-09-10 03:52:11 more
  • 網路滲透資料大全單——漏洞庫篇

    網路滲透資料大全單——漏洞庫篇漏洞庫 NVD ——美國國家漏洞庫 →http://nvd.nist.gov/。 CERT ——美國國家應急回應中心 →https://www.us-cert.gov/ OSVDB ——開源漏洞庫 →http://osvdb.org Bugtraq ——賽門鐵克 →ht ......

    uj5u.com 2020-09-10 03:52:15 more
  • 京準講述NTP時鐘服務器應用及原理

    京準講述NTP時鐘服務器應用及原理京準講述NTP時鐘服務器應用及原理 安徽京準電子科技官微——ahjzsz 北斗授時原理 授時是指接識訓通過某種方式獲得本地時間與北斗標準時間的鐘差,然后調整本地時鐘使時差控制在一定的精度范圍內。 衛星導航系統通常由三部分組成:導航授時衛星、地面檢測校正維護系統和用戶 ......

    uj5u.com 2020-09-10 03:52:25 more
  • 利用北斗衛星系統設計NTP網路時間服務器

    利用北斗衛星系統設計NTP網路時間服務器 利用北斗衛星系統設計NTP網路時間服務器 安徽京準電子科技官微——ahjzsz 概述 NTP網路時間服務器是一款支持NTP和SNTP網路時間同步協議,高精度、大容量、高品質的高科技時鐘產品。 NTP網路時間服務器設備采用冗余架構設計,高精度時鐘直接來源于北斗 ......

    uj5u.com 2020-09-10 03:52:35 more
  • 詳細解讀電力系統各種對時方式

    詳細解讀電力系統各種對時方式 詳細解讀電力系統各種對時方式 安徽京準電子科技官微——ahjzsz,更多資料請添加VX 衛星同步時鐘是我京準公司開發研制的應用衛星授時時技術的標準時間顯示和發送的裝置,該裝置以M國全球定位系統(GLOBAL POSITIONING SYSTEM,縮寫為GPS)或者我國北 ......

    uj5u.com 2020-09-10 03:52:45 more
  • 如何保證外包團隊接入企業內網安全

    不管企業規模的大小,只要企業想省錢,那么企業的某些服務就一定會采用外包的形式,然而看似美好又經濟的策略,其實也有不好的一面。下面我通過安全的角度來聊聊使用外包團的安全隱患問題。 先看看什么服務會使用外包的,最常見的就是話務/客服這種需要大量重復性、無技術性的服務,或者是一些銷售外包、特殊的職能外包等 ......

    uj5u.com 2020-09-10 03:52:57 more
  • PHP漏洞之【整型數字型SQL注入】

    0x01 什么是SQL注入 SQL是一種注入攻擊,通過前端帶入后端資料庫進行惡意的SQL陳述句查詢。 0x02 SQL整型注入原理 SQL注入一般發生在動態網站URL地址里,當然也會發生在其它地發,如登錄框等等也會存在注入,只要是和資料庫打交道的地方都有可能存在。 如這里http://192.168. ......

    uj5u.com 2020-09-10 03:55:40 more
  • [GXYCTF2019]禁止套娃

    git泄露獲取原始碼 使用GET傳參,引數為exp 經過三層過濾執行 第一層過濾偽協議,第二層過濾帶引數的函式,第三層過濾一些函式 preg_replace('/[a-z,_]+\((?R)?\)/', NULL, $_GET['exp'] (?R)參考當前正則運算式,相當于匹配函式里的引數 因此傳遞 ......

    uj5u.com 2020-09-10 03:56:07 more
  • 等保2.0實施流程

    流程 結論 ......

    uj5u.com 2020-09-10 03:56:16 more
最新发布
  • 使用Django Rest framework搭建Blog

    在前面的Blog例子中我們使用的是GraphQL, 雖然GraphQL的使用處于上升趨勢,但是Rest API還是使用的更廣泛一些. 所以還是決定回到傳統的rest api framework上來, Django rest framework的官網上給了一個很好用的QuickStart, 我參考Qu ......

    uj5u.com 2023-04-20 08:17:54 more
  • 記錄-new Date() 我忍你很久了!

    這里給大家分享我在網上總結出來的一些知識,希望對大家有所幫助 大家平時在開發的時候有沒被new Date()折磨過?就是它的諸多怪異的設定讓你每每用的時候,都可能不小心踩坑。造成程式意外出錯,卻一下子找不到問題出處,那叫一個煩透了…… 下面,我就列舉它的“四宗罪”及應用思考 可惡的四宗罪 1. Sa ......

    uj5u.com 2023-04-20 08:17:47 more
  • 使用Vue.js實作文字跑馬燈效果

    實作文字跑馬燈效果,首先用到 substring()截取 和 setInterval計時器 clearInterval()清除計時器 效果如下: 實作代碼如下: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta ......

    uj5u.com 2023-04-20 08:12:31 more
  • JavaScript 運算子

    JavaScript 運算子/運算子 在 JavaScript 中,有一些運算子可以使代碼更簡潔、易讀和高效。以下是一些常見的運算子: 1、可選鏈運算子(optional chaining operator) ?.是可選鏈運算子(optional chaining operator)。?. 可選鏈操 ......

    uj5u.com 2023-04-20 08:02:25 more
  • CSS—相對單位rem

    一、概述 rem是一個相對長度單位,它的單位長度取決于根標簽html的字體尺寸。rem即root em的意思,中文翻譯為根em。瀏覽器的文本尺寸一般默認為16px,即默認情況下: 1rem = 16px rem布局原理:根據CSS媒體查詢功能,更改根標簽的字體尺寸,實作rem單位隨螢屏尺寸的變化,如 ......

    uj5u.com 2023-04-20 08:02:21 more
  • 我的第一個NPM包:panghu-planebattle-esm(胖虎飛機大戰)使用說明

    好家伙,我的包終于開發完啦 歡迎使用胖虎的飛機大戰包!! 為你的主頁添加色彩 這是一個有趣的網頁小游戲包,使用canvas和js開發 使用ES6模塊化開發 效果圖如下: (覺得圖片太sb的可以自己改) 代碼已開源!! Git: https://gitee.com/tang-and-han-dynas ......

    uj5u.com 2023-04-20 08:01:50 more
  • 如何在 vue3 中使用 jsx/tsx?

    我們都知道,通常情況下我們使用 vue 大多都是用的 SFC(Signle File Component)單檔案組件模式,即一個組件就是一個檔案,但其實 Vue 也是支持使用 JSX 來撰寫組件的。這里不討論 SFC 和 JSX 的好壞,這個仁者見仁智者見智。本篇文章旨在帶領大家快速了解和使用 Vu ......

    uj5u.com 2023-04-20 08:01:37 more
  • 【Vue2.x原始碼系列06】計算屬性computed原理

    本章目標:計算屬性是如何實作的?計算屬性快取原理以及洋蔥模型的應用?在初始化Vue實體時,我們會給每個計算屬性都創建一個對應watcher,我們稱之為計算屬性watcher ......

    uj5u.com 2023-04-20 08:01:31 more
  • http1.1與http2.0

    一、http是什么 通俗來講,http就是計算機通過網路進行通信的規則,是一個基于請求與回應,無狀態的,應用層協議。常用于TCP/IP協議傳輸資料。目前任何終端之間任何一種通信方式都必須按Http協議進行,否則無法連接。tcp(三次握手,四次揮手)。 請求與回應:客戶端請求、服務端回應資料。 無狀態 ......

    uj5u.com 2023-04-20 08:01:10 more
  • http1.1與http2.0

    一、http是什么 通俗來講,http就是計算機通過網路進行通信的規則,是一個基于請求與回應,無狀態的,應用層協議。常用于TCP/IP協議傳輸資料。目前任何終端之間任何一種通信方式都必須按Http協議進行,否則無法連接。tcp(三次握手,四次揮手)。 請求與回應:客戶端請求、服務端回應資料。 無狀態 ......

    uj5u.com 2023-04-20 08:00:32 more