繁体   English   中英

Google App Engine 上的 NestJS 项目显示错误“无法写入文件”

[英]NestJS Project on Google App Engine shows error “Could not write file”

我尝试使用标准 env 实例在应用引擎中部署我的 nestJS 应用程序。 但我收到了这个错误:

0mCould not write file '/workspace/dist/my/ts/file': EROFS: read-only file system, open '/workspace/dist/my/ts/file'. 

我知道 nodejs 只能在 /tmp 目录中执行写入。

我的问题是:如何将工作区文件夹(由云构建创建)放入 tmp 文件夹

这是我的app.yaml

runtime: nodejs12
env: standard

这是我的package.json

{
  "name": "elengui-api",
  "version": "2.0.0",
  "description": "",
  "author": "",
  "private": true,
  "license": "UNLICENSED",
  "scripts": {
    "prebuild": "rimraf dist",
    "build": "npx @nestjs/cli build",
    "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
    "start": "npx @nestjs/cli start",
    "start:dev": "npx @nestjs/cli start --watch",
    "start:debug": "npx @nestjs/cli start --debug --watch",
    "start:prod": "node dist/main",
    "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
    "test": "jest",
    "test:watch": "jest --watch",
    "test:cov": "jest --coverage",
    "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
    "test:e2e": "jest --config ./test/jest-e2e.json",
    "gcp-build": "npm run build",
    "deploy": "gcloud app deploy"
  },
  "dependencies": {
    "@hapi/joi": "^17.1.1",
    "@nestjs/common": "^7.5.1",
    "@nestjs/config": "^0.6.3",
    "@nestjs/core": "^7.5.1",
    "@nestjs/jwt": "^7.2.0",
    "@nestjs/mapped-types": "^0.3.0",
    "@nestjs/passport": "^7.1.5",
    "@nestjs/platform-express": "^7.5.1",
    "@nestjs/schedule": "^0.4.3",
    "@nestjs/swagger": "^4.7.13",
    "@nestjs/throttler": "^1.1.3",
    "@nestjs/typeorm": "^7.1.5",
    "@types/bcrypt": "^3.0.0",
    "@types/cookie-parser": "^1.4.2",
    "@types/hapi__joi": "^17.1.6",
    "@types/nodemailer": "^6.4.0",
    "@types/passport": "^1.0.6",
    "@types/passport-jwt": "^3.0.4",
    "@types/passport-local": "^1.0.33",
    "bcrypt": "^5.0.0",
    "class-transformer": "^0.4.0",
    "class-validator": "^0.13.1",
    "cookie-parser": "^1.4.5",
    "crypto-random-string": "^3.3.1",
    "csurf": "^1.11.0",
    "express": "^4.17.1",
    "hbs": "^4.1.1",
    "helmet": "^4.4.1",
    "mysql2": "^2.2.5",
    "nodemailer": "^6.5.0",
    "passport": "^0.4.1",
    "passport-jwt": "^4.0.0",
    "passport-local": "^1.0.0",
    "path": "^0.12.7",
    "reflect-metadata": "^0.1.13",
    "rimraf": "^3.0.2",
    "rxjs": "^6.6.3",
    "swagger-ui-express": "^4.1.6",
    "typeorm": "^0.2.31"
  },
  "devDependencies": {
    "@nestjs/cli": "^7.5.4",
    "@nestjs/schematics": "^7.1.3",
    "@nestjs/testing": "^7.5.1",
    "@types/cron": "^1.7.2",
    "@types/express": "^4.17.11",
    "@types/jest": "^26.0.15",
    "@types/node": "^14.14.6",
    "@types/supertest": "^2.0.10",
    "@typescript-eslint/eslint-plugin": "^4.6.1",
    "@typescript-eslint/parser": "^4.6.1",
    "eslint": "^7.12.1",
    "eslint-config-prettier": "7.2.0",
    "eslint-plugin-prettier": "^3.1.4",
    "jest": "^26.6.3",
    "prettier": "^2.1.2",
    "supertest": "^6.0.0",
    "ts-jest": "^26.4.3",
    "ts-loader": "^8.0.8",
    "ts-node": "^9.0.0",
    "tsconfig-paths": "^3.9.0",
    "typescript": "^4.0.5"
  },
  "jest": {
    "moduleFileExtensions": [
      "js",
      "json",
      "ts"
    ],
    "rootDir": "src",
    "testRegex": ".*\\.spec\\.ts$",
    "transform": {
      "^.+\\.(t|j)s$": "ts-jest"
    },
    "collectCoverageFrom": [
      "**/*.(t|j)s"
    ],
    "coverageDirectory": "../coverage",
    "testEnvironment": "node"
  }
}

尝试写入与/tmp不同的目录来解释此错误。

官方文档包含以下内容:

虽然 Cloud Storage 是在 App Engine 中读写文件的推荐解决方案,但如果您的应用只需要写入临时文件,您可以使用标准的 Node.js 方法将文件写入名为 /tmp 的目录。

所以这是错误,您的代码似乎正在尝试使用错误消息中提到的目录。 我手头没有游乐场,但我想这与使用npxstart脚本有关。 您应该改用node <your-app.js> 我发现了不同的问题,问题海报证实了这一点。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM