https://pulumi.com logo
Title
a

acceptable-stone-35112

03/09/2021, 2:20 PM
It seems like this problem happens when trying to run transformations defined in different project (I have them in other repo published as npm, so I can reuse in all projects) registerStackTransformation fails with following exception. how come that stack is not initialized in my index.ts when console.log(pulumi.getStack()) returns correct stack name? Error: The root stack resource was referenced before it was initialized.         at Object.registerStackTransformation (..... \node_modules\@pulumi\pulumi\runtime\stack.js:211:15)
l

little-cartoon-10569

03/09/2021, 8:20 PM
Are you calling registerStackTransformation in the other project? It's fine to define the transforming function in the other project, but I think you need to call registerStackTransformation in the project that defines the stack.
a

acceptable-stone-35112

03/29/2021, 7:29 AM
yeah. in other project and I can't say I like the idea to copy those registers to all projects and instruct every developer to use same registers in every project instead of just calling registerCommonTransforms() or smth like that in index.ts
l

little-cartoon-10569

03/29/2021, 7:32 PM
Calling the function from index.ts should be fine, I think. So long as the stack context is that of the calling project, it should be all good. That is, in order to use the transformations in project A, the registerCommonTransforms() function defined in project B needs to be exported (and probably not from its index.ts, since you won't want to load that in project A), and called from project A.
a

acceptable-stone-35112

03/29/2021, 7:51 PM
that's pretty much what I was trying to do. register function exported by shared project and that's what was causing the problem
l

little-cartoon-10569

03/29/2021, 8:10 PM
Unless it's exported with a reference to its "source" project, that should be fine.
I have my version of this code in a module that isn't "in" a project, but that shouldn't make a difference. Code isn't "in" a project unless it's being invoked during a project's ... invocation ¯\_(ツ)_/¯
You may have to experiment with parameters, location, etc. Something is causing it, but I can't tell what.
a

acceptable-stone-35112

03/30/2021, 9:19 AM
well, its referenced as npm package
both registerStackTransform and related code are in that npm package
l

little-cartoon-10569

03/30/2021, 7:40 PM
I haven't done it that way. If you import from the file system instead of a package, does it work? I've only ever imported from the filesystem (I use a monorepo).
a

acceptable-stone-35112

04/01/2021, 9:42 AM
importing from FS works. with npm even referencing npm locally doesn't work. in fact there's an open issue on it in different context https://github.com/pulumi/pulumi/issues/4669