echoing-zebra-28421
06/27/2021, 11:52 PMError reading file 'infra/package.json' when computing package dependencies. Error: ENOENT: no such file or directory, open '/infra/package.json'
My dir:
- project
...
- infra
- Pulumi.yaml
- tsconfig.json
...
- src
...
- package.json
- tsconfig.json
I need to have the package.json at that place in my directory.
Any help or alternatives to solve the problem will be welcome.
I'm using @pulumi/pulumi: "^3.4.0"
this error occurs when i run pulumi preview --cwd infra
I run that command in the root of my project.
the problem occurs when I try to use aws.lambda.CallbackFunction
little-cartoon-10569
06/27/2021, 11:54 PMechoing-zebra-28421
06/28/2021, 12:04 AM- project
...
- infra
- Pulumi.yaml
- tsconfig.json
...
- src
...
- package.json
- tsconfig.json
in my package.json
{
...
"devDependencies": {
"@pulumi/aws": "^4.0.0",
"@pulumi/pulumi": "^3.0.0",
...
},
"main": "infra/index.ts",
"dependencies": {
"axios": "^0.21.1"
}
}
infra/index.ts
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
const stack = pulumi.getStack();
const name = `test-${stack}`;
const lambdaRole = new aws.iam.Role(`${name}-role`, {
assumeRolePolicy: {
Version: "2012-10-17",
Statement: [
{
Action: "sts:AssumeRole",
Principal: {
Service: "<http://lambda.amazonaws.com|lambda.amazonaws.com>",
},
Effect: "Allow",
Sid: "",
},
],
},
});
const lambdaRoleAttachment = new aws.iam.RolePolicyAttachment(
`${name}-role-attachment`,
{
role: lambdaRole,
policyArn: aws.iam.ManagedPolicy.AWSLambdaBasicExecutionRole,
},
);
const lambda = new aws.lambda.CallbackFunction(`${name}-lambda`, {
callback: (foo, bar) => {
console.log(foo, bar);
},
});
export const test = lambda.arn;
when i run: pulumi preview --cwd infra
My error:
Error reading file 'infra/package.json' when computing package dependencies. Error: ENOENT: no such file or directory, open '/infra/package.json'
but when I comment on that function (aws.lambda.CallbackFunction) or use another kind of simple example. That command works fine for me.error: Error: Error reading file 'alex-test/infra/package.json' when computing package dependencies. Error: ENOENT: no such file or directory, open 'alex-test/infra/package.json'
at readFile (alex-test/node_modules/@pulumi/pulumi/runtime/closure/codePaths.js:167:19)
at computeDependenciesDirectlyFromPackageFile (alex-test/node_modules/@pulumi/pulumi/runtime/closure/codePaths.js:150:22)
at alex-test/node_modules/@pulumi/pulumi/runtime/closure/codePaths.js:115:36
at alex-test/node_modules/read-package-tree/rpt.js:162:20
little-cartoon-10569
06/28/2021, 12:40 AMnpm install
in the project directory. You can avoid duplicating package.json but afaict you need to duplicate your _node___modules_ directory.echoing-zebra-28421
06/28/2021, 1:43 AMnpm install
to create the axios dependency.
With that duplication of the package.json it works fine for me.
my structure would look like this:
- project
...
- infra
- Pulumi.yaml
- package.json
- tsconfig.json
...
- src
...
- package.json
- tsconfig.json
in infra/package.json
{
"dependencies": {
"axios": "^0.21.1"
}
}
I hope that at some point that issue is solved.
The symbolic link did not work as expected. But hey, if you find a better, more effective solution, I would appreciate it.little-cartoon-10569
06/28/2021, 2:01 AMechoing-zebra-28421
06/28/2021, 2:09 AMlittle-cartoon-10569
06/28/2021, 2:12 AMechoing-zebra-28421
06/28/2021, 2:21 AM- Pulumi.yaml
- index.ts
...
where the index.ts use the aws.lambda.CallbackFunction
in the root you must have the package.json
with all the dependencies of pulumi.
and when this command is run:
pulumi preview --cwd infra
works correctly.
If you try to create a project with that structure, it will surely give you that error that I get. But it is when the aws.lambda.CallbackFunction
is used because with another example that this one in the documentation works well that folder and file structurelittle-cartoon-10569
06/28/2021, 2:53 AM