Adam Fanello
01/21/2022, 6:58 PMError: ENOENT: no such file or directory, open '/Users/adam/dev/casa/cloud/.build/cfn-types-2-classes.json'
at Object.openSync (node:fs:585:3)
at Object.readFileSync (node:fs:453:35)
at Object.readJsonSync (/Users/adam/dev/casa/node_modules/aws-cdk-lib/cloudformation-include/lib/file-utils.ts:5:27)
at loadCfnTypeToL1Mapping (/Users/adam/dev/casa/node_modules/aws-cdk-lib/cloudformation-include/lib/cfn-type-to-l1-mapping.ts:24:17)
at Object.lookup (/Users/adam/dev/casa/node_modules/aws-cdk-lib/cloudformation-include/lib/cfn-type-to-l1-mapping.ts:17:26)
at CfnInclude4.getOrCreateResource (/Users/adam/dev/casa/node_modules/aws-cdk-lib/cloudformation-include/lib/cfn-include.ts:503:49)
at new CfnInclude4 (/Users/adam/dev/casa/node_modules/aws-cdk-lib/cloudformation-include/lib/cfn-include.ts:93:12)
at new IotDeviceStack (/Users/adam/dev/casa/cloud/src/stacks/iot-device/iot-device.stack.ts:17:5)
at Object.main (/Users/adam/dev/casa/cloud/src/stacks/index.ts:117:23)
at Object.<anonymous> (/Users/adam/dev/casa/cloud/.build/run.js:94:16)
Adam Fanello
01/21/2022, 7:00 PMimport { CfnInclude } from "aws-cdk-lib/cloudformation-include";
new CfnInclude(this, "iot-device-stack", {
templateFile: "src/stacks/iot-device/iot-device.yaml",
parameters: {
namespace: prefix.substring(0, prefix.length - 1),
},
});
thdxr
01/21/2022, 7:07 PMAdam Fanello
01/21/2022, 7:09 PMthdxr
01/21/2022, 7:10 PMAdam Fanello
01/21/2022, 7:12 PMAdam Fanello
01/21/2022, 7:13 PMnode_modules/aws-cdk-lib/cloudformation-include/cfn-types-2-classes.json
Adam Fanello
01/21/2022, 7:51 PMthdxr
01/21/2022, 7:52 PMsst build
rightAdam Fanello
01/21/2022, 7:52 PMAdam Fanello
01/21/2022, 9:40 PMfunction loadCfnTypeToL1Mapping() {
return futils.readJsonSync(path.join(__dirname, "..", "cfn-types-2-classes.json"))
}
The .json file is indeed one directory up from this source in node_modules, but at runtime this is executing from .build/lib/index.js
Frank
aws-cdk-lib
as an esbuild external module resolve this?thdxr
01/22/2022, 2:31 PMthdxr
01/22/2022, 2:31 PMFrank
package.json
are set to external when bundling with esbuild. Can you check if you have aws-cdk-lib
listed in your package.json
(the one in the same folder as sst.json
)?Adam Fanello
01/24/2022, 4:32 PM{
"name": "@pkg/cloud",
"version": "1.0.0",
"description": "Serverless project for AWS Lambdas written in Typescript",
"author": "Onica",
"private": true,
"scripts": {
"analyze": "npm run build && npm run lint && npm test && prettier -c . --ignore-path ../.prettierignore",
"clean": "rm -rf .build .sst cdk.out coverage dist",
"lint": "eslint src",
"test": "jest",
"test:watch": "jest --watch --runInBand",
"start": "sst start --stage $DEPLOY_ENVIRONMENT",
"build": "tsc && sst build --stage $DEPLOY_ENVIRONMENT",
"deploy": "sst deploy --stage $DEPLOY_ENVIRONMENT",
"remove": "sst remove --stage $DEPLOY_ENVIRONMENT",
"run:script": "ts-node --transpile-only"
},
"dependencies": {
"@aws-sdk/client-ssm": "^3.45.0",
"@aws/dynamodb-batch-iterator": "^0.7.1",
"@aws/dynamodb-query-iterator": "^0.7.1",
"@middy/core": "^2.5.4",
"@middy/http-cors": "^2.5.4",
"@middy/http-event-normalizer": "^2.5.4",
"@middy/http-header-normalizer": "^2.5.4",
"@middy/http-json-body-parser": "^2.5.4",
"@sailplane/expiring-value": "^2.0.0",
"@sailplane/injector": "^2.0.1",
"@sailplane/lambda-utils": "^4.0.0",
"@sailplane/logger": "^3.0.0",
"@sailplane/state-storage": "^2.0.0",
"bottlejs": "^1.7.2",
"http-errors": "^1.8.1",
"jsonwebtoken": "^8.5.1",
"jwk-to-pem": "^2.0.5",
"node-fetch": "^2.6.6",
"node-forge": "^0.10.0",
"temporal-constants": "^1.1.2",
"temporal-types": "^1.2.0"
},
"devDependencies": {
"@serverless-stack/cli": "0.60.4",
"@serverless-stack/resources": "0.60.4",
"@stoplight/spectral-cli": "^6.1.0",
"@types/aws-lambda": "^8.10.89",
"@types/http-errors": "^1.8.1",
"@types/jest": "^26.0.24",
"@types/jsonwebtoken": "^8.5.6",
"@types/jwk-to-pem": "^2.0.1",
"@types/node-fetch": "^2.5.12",
"@types/node-forge": "^0.10.8",
"@typescript-eslint/eslint-plugin": "^5.8.1",
"@typescript-eslint/parser": "^5.8.1",
"amazon-cognito-identity-js": "^4.6.3",
"aws-sdk": "^2.1052.0",
"eslint": "^8.6.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-jest": "^25.3.4",
"eslint-plugin-jsdoc": "^37.5.1",
"eslint-plugin-prefer-arrow": "^1.2.3",
"jest": "^26.6.3",
"jest-create-mock-instance": "^2.0.0",
"jsonc-parser": "^3.0.0",
"openapi3-ts": "^2.0.1",
"punycode": "^2.1.1",
"rxjs": "^7.4.0",
"source-map-support": "^0.5.21",
"ts-jest": "^26.5.6",
"ts-node": "^10.4.0",
"typescript": "4.5.x",
"yaml": "^1.10.2"
}
}
Frank
npx sst add-cdk aws-cdk-lib
? That will add aws-cdk-lib
to your package.json
. And that should fix this.Frank
package.json
are set as external
, so they shouldn’t be transpiled, so __dirname
will point to the right spot.Adam Fanello
01/24/2022, 6:25 PM"aws-cdk-lib": "2.7.0",
thdxr
01/24/2022, 6:28 PMFrank
Frank
Adam Fanello
01/24/2022, 6:51 PMAdam Fanello
01/24/2022, 6:52 PMFrank
aws-cdk-lib
as external by default. Will release this later today https://github.com/serverless-stack/serverless-stack/pull/1298Frank