(core): `CustomResourceProvider` writes to `node_modules`
See original GitHub issueWhat is the problem?
On instantiation, the CustomResourceProvider
class writes a file into the node_modules
directory instead of creating a safe temporary directory to stage local assets. What’s more, for users of Yarn berry
with PnP, node_modules
is a read-only ZipFS filesystem, which raises an exception when the write is attempted.
Reproduction Steps
const bucket = new s3.Bucket(this, 'MyBucket', {
removalPolicy: cdk.RemovalPolicy.DESTROY,
autoDeleteObjects: true, // <-- this line causes synth to fail, uses CustomResourceProvider
});
What did you expect to happen?
A stack would be synthesized containing a custom resource to delete objects from the above bucket in the event the bucket is ever removed from the stack.
What actually happened?
me@host % yarn cdk synthesize
/Users/me/workspace/cdk/.pnp.cjs:17448
return Object.assign(new Error(`${code}: ${message}`), {
^
Error: EROFS: read-only filesystem, open '/node_modules/@aws-cdk/aws-s3/lib/auto-delete-objects-handler/__entrypoint__.js'
at makeError (/Users/me/workspace/cdk/.pnp.cjs:17448:24)
at EROFS (/Users/me/workspace/cdk/.pnp.cjs:17478:10)
at ZipFS.prepareWriteFile (/Users/me/workspace/cdk/.pnp.cjs:19787:30)
at ZipFS.writeFileSync (/Users/me/workspace/cdk/.pnp.cjs:19775:14)
at fallback (/Users/me/workspace/cdk/.pnp.cjs:20617:14)
at /Users/me/workspace/cdk/.pnp.cjs:20637:18
at /Users/me/workspace/cdk/.pnp.cjs:20951:58
at ZipOpenFS.getZipSync (/Users/me/workspace/cdk/.pnp.cjs:21096:14)
at ZipOpenFS.makeCallSync (/Users/me/workspace/cdk/.pnp.cjs:20951:17)
at /Users/me/workspace/cdk/.pnp.cjs:20631:19 {
code: 'EROFS'
}
Subprocess exited with error 1
CDK CLI Version
1.131.0 (build 7560c79)
Framework Version
1.131.0
Node.js Version
v16.3.0
OS
macOS Big Sur 11.6.1
Language
Typescript
Language Version
TypeScript (4.4.4)
Other information
Previously reported as a problem in the aws-s3
module, closed by that module’s maintainer:
https://github.com/aws/aws-cdk/issues/16552
Most likely source of the problem:
A temporary directory should be created (the core
module provides FileSystem.mkdtemp
) and the code should be written to that instead of assuming that the module directory can accept writes. Specifics for Yarn 2.x can be viewed at:
Issue Analytics
- State:
- Created 2 years ago
- Reactions:15
- Comments:7 (2 by maintainers)
Top GitHub Comments
I lied. Referencing the original version above only passes
node
’s cursory checks and doesn’t actually build properly. The files need to be copied. A better version follows (and appears to work):I agree this is poor behavior.