NodeJS 是否更改节点缓存的位置?

pgpifvop  于 2023-08-04  发布在  Node.js
关注(0)|答案(1)|浏览(96)

我正在尝试使用Serverless将容器化的nodejs应用程序部署到AWS Lambda。
它会部署,但我一触发它就遇到了[Error: EROFS: read-only file system, mkdir '/directus/.cache'],我尝试创建文件夹,现在它是[Error: EROFS: read-only file system, open '.cache/tmp/760261a8']
我知道为什么,Lambda只能在/tmp文件夹中写入,我搜索了是否有方法可以更改节点缓存的位置,因为我假设它是node,因为这行node:internal/process/promises:288,但我什么也没找到。
以下是完整的错误:

2023-07-05T17:19:59.015+02:00   node:internal/process/promises:288

2023-07-05T17:19:59.015+02:00   triggerUncaughtException(err, true /* fromPromise */);

2023-07-05T17:19:59.015+02:00   ^

2023-07-05T17:19:59.015+02:00   [Error: EROFS: read-only file system, mkdir '/directus/.cache'] {

2023-07-05T17:19:59.015+02:00   errno: -30,

2023-07-05T17:19:59.015+02:00   code: 'EROFS',

2023-07-05T17:19:59.015+02:00   syscall: 'mkdir',

2023-07-05T17:19:59.015+02:00   path: '/directus/.cache'

2023-07-05T17:19:59.015+02:00   }

2023-07-05T17:19:59.015+02:00   Node.js v18.16.1

2023-07-05T17:19:59.910+02:00   node:internal/process/promises:288

2023-07-05T17:19:59.910+02:00   triggerUncaughtException(err, true /* fromPromise */);

2023-07-05T17:19:59.910+02:00   ^

2023-07-05T17:19:59.910+02:00   [Error: EROFS: read-only file system, mkdir '/directus/.cache'] {

2023-07-05T17:19:59.910+02:00   errno: -30,

2023-07-05T17:19:59.910+02:00   code: 'EROFS',

2023-07-05T17:19:59.910+02:00   syscall: 'mkdir',

2023-07-05T17:19:59.910+02:00   path: '/directus/.cache'

2023-07-05T17:19:59.910+02:00   }

2023-07-05T17:19:59.910+02:00   Node.js v18.16.1

2023-07-05T17:19:59.935+02:00   START RequestId: 46921599-988b-4341-9198-62c8e646ed83 Version: $LATEST

2023-07-05T17:19:59.936+02:00   RequestId: 46921599-988b-4341-9198-62c8e646ed83 Error: Runtime exited with error: exit status 1 Runtime.ExitError

2023-07-05T17:19:59.936+02:00   END RequestId: 46921599-988b-4341-9198-62c8e646ed83

2023-07-05T17:19:59.936+02:00   REPORT RequestId: 46921599-988b-4341-9198-62c8e646ed83 Duration: 859.43 ms Billed Duration: 860 ms Memory Size: 1024 MB Max Memory Used: 30 MB

字符串
我在nodejs方面经验不足,不知道现在该怎么做,有什么帮助吗?.
应用程序是Directus,我知道它不是为Lambdas设计的,但我认为容器应该可以工作,我只是尝试一下,发现被这个错误卡住很奇怪。
我已经在代码中搜索错误的位置,但没有结果。尝试将整个项目更改为/tmp,令人惊讶的是,它无法运行,因为/tmp被删除。(duh)
我尝试了以下env变量:

npm_config_cache="/tmp/.npm" \
    NODE_CACHE="/tmp/.cache" \


这里的https://github.com/directus/directus与我使用的Dockerfile几乎相同

zpqajqem

zpqajqem1#

有点晚了,但我也遇到了同样的问题。Directus使用find-cache-dir为node-fetch-cache创建一个缓存目录,仅用于搜索更新,并且它不能被禁用(目前)。有了这些信息,我就能够将CACHE_DIR环境变量设置为/tmp,这使得它在OpenShift上启动,OpenShift也不允许对文件系统进行写访问。

相关问题