https://pulumi.com logo
#typescript
Title
# typescript
l

little-cartoon-10569

01/18/2022, 9:52 PM
Pulumi seems to be running my TS code without transpiling it according to the directions in tsconfig.json. I've just added baseUrl/paths/moduleAliases, but it's complaining that it can't find the JS files in dist/.../*.js...
How can I require that Pulumi (or tsc/yarn/npm?) transpiles every run?
m

millions-furniture-75402

01/18/2022, 9:56 PM
Are you talking about your application, or Pulumi plan?
l

little-cartoon-10569

01/18/2022, 9:57 PM
I want pulumi preview to (potentially) update dist/.../*.js (if my .ts files have changed).
My tsconfig.json says
outDir: "./dist"
. Something has put files there. But I don't know what. Certainly there should be many more files.
m

millions-furniture-75402

01/18/2022, 9:59 PM
How are you deploying your code? Using a Lambda Callback Function?
l

little-cartoon-10569

01/18/2022, 10:01 PM
No,
pulumi up
...
Maybe we're talking at cross purposes?
My Pulumi code is in typescript. It uses baseUrl/paths in its imports (
"@myorg": "./src/pulumi/"
and similar). VSCode and typescript honour this.
However the JS that's actually being run is complaining that it can't find module "@myorg", since JS doesn't know about paths.
So I've added _moduleAliases saying "@myorg" is "./dist/src/pulumi/", which is where I expect the transpiled JS code to go.
But it's not there.
Interestingly, I tried compiling it manually and it turns out
tsc
isn't even installed! I don't know how Pulumi is running my typescript...
m

millions-furniture-75402

01/18/2022, 10:05 PM
I'm finding this hard to understand without an example, but these two documents should add clarity about how Pulumi's typescript / tsconfig.json support work, and function serialization for determining which dependencies get magically deployed with it: https://www.pulumi.com/docs/intro/concepts/function-serialization/ https://www.pulumi.com/docs/intro/languages/javascript/#3-create-tsconfigjson Personally, I decouple the application build process from Pulumi's magic.
Pulumi's engine has typescript support
you can choose to disable it.
l

little-cartoon-10569

01/18/2022, 10:05 PM
No function serialization is involved. I'm talking about the actual Pulumi program, not code to be run in the cloud.
m

millions-furniture-75402

01/18/2022, 10:05 PM
Ahh, okay
l

little-cartoon-10569

01/18/2022, 10:07 PM
My issue is that there are no (findable) JS files that contain the transpiled TS code of my Pulumi program.
That 2nd link you posted has
"outDir": "bin"
in its recommended tsconfig.json, but afaict, the bin dir is not being updated
m

millions-furniture-75402

01/18/2022, 10:10 PM
Maybe you want this option? https://www.typescriptlang.org/docs/handbook/module-resolution.html
Note: 
node
 module resolution is the most-commonly used in the TypeScript community and is recommended for most projects. If you are having resolution problems with `import`s and `export`s in TypeScript, try setting 
moduleResolution: "node"
 to see if it fixes the issue.
l

little-cartoon-10569

01/18/2022, 10:12 PM
Yep, that's what I'm using. Specifically, the part here: https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping
Unfortanuately, only the typescript part works. The lower-level javascript part isn't yet working.
m

millions-furniture-75402

01/18/2022, 10:14 PM
Okay, so you have a TypeScript Pulumi plan that's trying to import JavaScript, and it's failing to run the JavaScript imports on the TypeScript language host?
l

little-cartoon-10569

01/18/2022, 10:19 PM
No.
I'm only running a normal typescript Pulumi program, nothing else.
Typescript isn't an interpreted language, it's transpiled to javascript, then interpreted.
I am using a typescript-only technology to make my files easier to read.
In the transpiled JS files, this isn't recognized, so I'm using a 2nd, JS technology, to support it.
However, Pulumi cannot find the transpiled JS files which I believe it should be running.
I presume it's transpiling them into memory, and this must be breaking stuff? But I don't know.
m

millions-furniture-75402

01/18/2022, 10:22 PM
l

little-cartoon-10569

01/18/2022, 10:25 PM
Hmm. Not exactly the same, but adopting that might resolve the issue incidentally.. plus I like modules, so I'll make this changes anyway 🙂
Thanks for finding it.
👍 1
That lead me down another rabbit hole. Big warren. Gave up, raised an issue: https://github.com/pulumi/pulumi/issues/8787
m

mammoth-art-6111

02/23/2022, 6:30 PM
i just ran into this as well. so far i've been able to ram path-mapping into Pulumi by using
tsconfig-paths
and doing the path mapping instantiation in index.ts as it gets read by Pulumi (and similarly, I can run Jest via moduleMapper), but static analysis of files still fails
using the bundled
tsserver
will always throw errors about modules missing
similarly,
tsc
will always throw the same errors