I recently upgraded to Pulumi v3.122.0, and now `p...
# general
d
I recently upgraded to Pulumi v3.122.0, and now
pulumi up
fails on one of my stacks with the error:
Copy code
error: Error: ENOENT: no such file or directory, stat '<stackname>'
        at Object.statSync (node:fs:1690:3)
        at resolveConfigPath (/home/rkeene/devel/project/node_modules/tsconfig-paths/src/tsconfig-loader.ts:90:9)
        at loadSyncDefault (/home/rkeene/devel/project/node_modules/tsconfig-paths/src/tsconfig-loader.ts:60:12)
        at tsConfigLoader (/home/rkeene/devel/project/node_modules/tsconfig-paths/src/tsconfig-loader.ts:47:20)
        at configLoader (/home/rkeene/devel/project/node_modules/tsconfig-paths/src/config-loader.ts:66:22)
        at Object.register (/home/rkeene/devel/project/node_modules/tsconfig-paths/src/register.ts:80:25)
        at Object.<anonymous> (/home/rkeene/devel/project/node_modules/tsconfig-paths/register.js:1:15)
        at Module._compile (node:internal/modules/cjs/loader:1256:14)
        at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
        at Object.require.extensions.<computed> [as .js] (/home/rkeene/devel/project/node_modules/ts-node/src/index.ts:1608:43)
It's not clear why it cares that there is no directory named
stackname
(where the actual value is the name of the stack, not the literal word "stackname") suddenly. It appears to be trying to locate a "tsconfig" file, but there has never been (nor will be) anything named "stackname"
l
Is there more in the stack trace? It looks like something is calling require(), but we can't see what. Also, this seems to be a #typescript-specific question.
d
That's the whole stack trace
It only started after upgrading Pulumi
l
You'll need to figure out which import/require is triggering it.. could be hard 😞
d
It fails in
@pulumi/pulumi/cmd/run/run
while calling
tsn.register()
here: https://github.com/pulumi/pulumi/blob/74e8928cff4f605a157d0991191bbf0b9b25967d/sdk/nodejs/cmd/run/run.ts#L262
l
That looks like the place that your project is being loaded. At a guess, I'd say the problem is within your project, on an
import
or
require
line. But how do find which one? I have no idea 😞
d
It's within Pulumi, not within my project.
tsn.register()
never returns, since it throws that error
No code from my project is ever run
l
Yes, because the problem happens as your typescript is being built.
Maybe a strict linter would find the same problem?
d
No, it's before any line of code of mine is run
That comes after
tsn.register()
l
I don't know what the order is. I'd have thought a file would need to be loaded in order to be transpiled, and it wouldn't be run until after that. And it's the loading or transpiling that's the problem.
d
First ts-node is loaded, then you give ts-node your program
l
Right, but that code snippet is pointing at your code, I guess? tsConfigPath is your code. Are you using ESM? I see that the snippt is specifying older defaults, like commonjs and es6.
d
tsConfigPath is a directory, which has the
tsconfig.json
file (which isn't code)
It's needed to load the options for ts-node (for which it resolves to an empty object, currently)
Just to extra sure, I deleted all my code and the error is still the same
l
Yes, I meant code path, sorry. I'm wondering if you need some options to override this registration. I use this in all my Pulumi.yamls:
Copy code
runtime:
  name: nodejs
  options:
    nodeargs: "--loader ts-node/esm --no-warnings --experimental-specifier-resolution=node"
d
The directory now only has a single file, called
tsconfig.json
I doubt it, since ts-node can emit ES6 (which is being done), so I do't need to use any special loader in addition to ts-node, which Pulumi (tries to) set up
l
Nice, you've narrowed it right now. Maybe try with a trivial tsconfig?
d
It was already pretty trivial...
l
Or maybe delete all your plugins, maybe one is corrupt, or conflicts with something
d
I've completely deleted
~/.pulumi
l
Wow. There's really nothing left to check then! But this isn't causing problems widely (no other posts here)... what else is left on your system that could be at fault?
Maybe your node_modules, bun.lockb, or something like that?
d
Deleting
tsconfig.js
caused it to do something different, but that different thing isn't working
Something is definitely broken within Pulumi...
My
Pulumi.yaml
has:
Copy code
name: project-cloud-deploy
description: Cloud Deployment
runtime: nodejs
main: deployment
l
Right, but it's pulumi on your system, or in some way that it interacts with your system. Since it's not being reported elsewhere (that I know about).
d
In
deployment/
I have
tsconfig.json
and
index.ts
If I delete index.ts, I get that error that started this thread
l
But it works if you don't delete index.ts?
d
If I delete tsconfig.json (and restore index.ts) instead
pulumi up
runs my main program -- (i.e., not
deployment/index.ts
, but
src/index.ts
from the program root)
In no case does it work
I think someone broke the usage of
main
within
Pulumi.yaml
l
What is the
main
property in your Pulumi.yaml? I don't see it in the docs,
I've never seen it before.
d
https://www.pulumi.com/docs/concepts/projects/project-file/ has it listed -- where did you not see it ?
l
d
Yeah, I don't think that is a normative document -- the normative document contains it
l
Yep, that makes sense. If you put Pulumi.yaml in deployment, does it work?
d
You mean get rid of
main
as well ? (since then it would refer to a directory that doesn't exist, since I don't have
deployment/deployment
)
l
Yes. Also: The docs (now) say this:
For Node.js projects, main can point to a .ts or .js file and behaves similarly to setting the main attribute in package.json. When the main property is set in Pulumi.yaml, it may be omitted from package.json (and vice-versa). When it exists in both Pulumi.yaml and package.json, the value in Pulumi.yaml takes precedence.
But you have a directory, not a .ts/.js file. Maybe change to deployment/index.ts?
d
No, it still runs
../src/index.ts
l
The docs say it should point to a file, and you're providing a directory and it doesn't work...
d
That gets me back to the original problem
Copy code
.../project/deployment> ls -l
total 20
-rw-r--r-- 1 rkeene rkeene 13076 Jul  9 18:36 index.ts
-rw-r--r-- 1 rkeene rkeene    70 Jul  9 18:45 tsconfig.json
.../project/deployment> cat tsconfig.json 
{
    "extends": "../tsconfig.json",
    "include": [ "index.ts" ],
}
.../project/deployment> cat ../Pulumi.yaml 
name: project-cloud-deploy
description: Cloud Deployment
runtime: nodejs
main: ./deployment/index.ts
.../project/deployment>
Copy code
.../project/deployment> cd ..
.../project> pulumi up
Previewing update (dev):
     Type                 Name                     Plan     Info
     pulumi:pulumi:Stack  project-cloud-deploy-dev           1 error; 111 messages

Diagnostics:
  pulumi:pulumi:Stack (jester-cloud-deploy-dev):
    error: Error: ENOENT: no such file or directory, stat 'project-cloud-deploy'
        at Object.statSync (node:fs:1690:3)
        at resolveConfigPath (/home/rkeene/devel/project/node_modules/tsconfig-paths/src/tsconfig-loader.ts:91:10)
        at loadSyncDefault (/home/rkeene/devel/project/node_modules/tsconfig-paths/src/tsconfig-loader.ts:61:7)
        at tsConfigLoader (/home/rkeene/devel/project/node_modules/tsconfig-paths/src/tsconfig-loader.ts:48:2)
        at configLoader (/home/rkeene/devel/project/node_modules/tsconfig-paths/src/config-loader.ts:66:22)
        at Object.register (/home/rkeene/devel/project/node_modules/tsconfig-paths/src/register.ts:80:25)
        at Object.<anonymous> (/home/rkeene/devel/project/node_modules/tsconfig-paths/register.js:1:15)
        at Module._compile (node:internal/modules/cjs/loader:1256:14)
        at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
        at Object.require.extensions.<computed> [as .js] (/home/rkeene/devel/project/node_modules/ts-node/src/index.ts:1612:11)
        at Module.load (node:internal/modules/cjs/loader:1119:32)
        at Function.Module._load (node:internal/modules/cjs/loader:960:12)
        at internalRequire (node:internal/modules/cjs/loader:174:19)
        at Function.Module._preloadModules (node:internal/modules/cjs/loader:1433:5)
        at Object.register (/home/rkeene/devel/project/node_modules/ts-node/src/index.ts:614:18)
        at Object.<anonymous> (/home/rkeene/devel/project/node_modules/@pulumi/cmd/run/run.ts:284:9)
        at Generator.next (<anonymous>)
        at /home/rkeene/devel/project/node_modules/@pulumi/pulumi/cmd/run/run.js:21:71
        at new Promise (<anonymous>)
        at __awaiter (/home/rkeene/devel/project/node_modules/@pulumi/pulumi/cmd/run/run.js:17:12)
        at Object.run (/home/rkeene/devel/project/node_modules/@pulumi/pulumi/cmd/run/run.js:222:12)
        at /home/rkeene/devel/project/node_modules/@pulumi/cmd/run/index.ts:163:57
        at processTicksAndRejections (node:internal/process/task_queues:95:5)
It's also worth noting that the only place
project-cloud-deploy
appears is within
Pulumi.yaml
(in the project root) -- that's literally the only place that string exists
Creating an empty directory named
deployment/project-cloud-deploy
resolved it
l
Huh. Weird.
And you think that
main
property is at fault? If you put a Pulumi.yaml without that in the same dir as index.ts, do you avoid the error? This definitely is a bug.
d
It still fails if I get rid of
main
and move
Pulumi*yaml
into
deployment
I think it's a bug in the way in something is calling tsn.register() with something related to the
name
in the
Pulumi.yaml
which it shouldn't
I tracked this down to an entry in
<root>/tsconfig.json
:
Copy code
{
...
	"ts-node": {
		"require": ["tsconfig-paths/register"]
	}
}
To resolve it, I added an override to the `deployment/tsconfig.json`:
Copy code
{
  "extends": "../tsconfig.json",
  "include": [
    "index.ts"
  ],
  "ts-node": {
    "require": []
  }
}
l
Nice, well done. It's the old help-desk trick: turn everything, then turn it back on (one by one...).
d
I also had to update
main
to specify
./deployment/index.ts
instead of just
deployment