Or rather, how can I use `target: "es2020"` and co...
# typescript
e
Or rather, how can I use
target: "es2020"
and compile the project myself, piping the output JS to Pulumi?
b
pulumi uses ts-node to automatically run `tsc`: https://github.com/TypeStrong/ts-node if you want to compile the JS yourself, you can set the following in your
Pulumi.yaml
Copy code
options
  typescript: false
https://www.pulumi.com/docs/reference/pulumi-yaml/
l
How do we then leverage this to deploy/
Manually compile and
pulumi up
?
Copy code
name: creatio-sync
description: Creatio Sync
runtime: nodejs
options:
  typescript: false
is my
Pulumi.yaml
If I run
npx tsc index.ts
it compiles the
index.js
But
pulumi up
still seems to be trying to use it
Do I need a change in my
package.json
or something too?
Either the options changed recently or I’m stupid, but it’s now
Copy code
runtime:
  name: nodejs
  options:
    typescript: false
but still no dice
b
when you say
pulumi up
seems to be trying to use it, do you mean your index.ts ?
e
I managed to get it working, but it is not that straight forward. my
tsconfig.json
specifies that the output dir should be
dist
which is ignored in
.gitignore
. Then I needed to tell Pulumi to use the JS file, which we can do so by adding the
main
property to the
package.json
. The thing is that unless we use
amd
as the
module
definition in
tsconfig
, TSC cannot combine all files into a single
index.js
file. To solve this, I did some bash magic and created the following command:
Copy code
"scripts": {
    "deploy": "tsc && sed -i '' \"s#\\\"main\\\": \\\".*,#\\\"main\\\": \\\"$(find dist -name 'index.js' -print -maxdepth 3 -quit)\\\",#\" package.json && pulumi up"
  },
l
sorry, yeah, and I’m assuming it is
e
This works for me, I guess the script should be slightly modified for others
my `tsconfig.json`:
Copy code
{
  "compilerOptions": {
    "strict": true,
    "outDir": "dist",
    "target": "es2020",
    "module": "commonjs",
    "moduleResolution": "node",
    "sourceMap": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "esModuleInterop": true,
    "resolveJsonModule": true,
    "pretty": true,
    "noFallthroughCasesInSwitch": true,
    "noImplicitReturns": true,
    "strictNullChecks": true,
    "noImplicitAny": true,
    "noImplicitThis": true,
    "alwaysStrict": true,
    "strictPropertyInitialization": false,
    "forceConsistentCasingInFileNames": true,
    "removeComments": true
  }
}
l
My exact issue is
Copy code
Diagnostics:
  pulumi:pulumi:Stack (creatio-sync-production):
    error: Running program '/Users/james/projects/creatio/creatio-sync/deploy' failed with an unhandled exception:
    /Users/james/projects/creatio/creatio-sync/deploy/node_modules/@devops/pulumi-utils/index.ts:1
    import * as fs from 'fs'
    ^^^^^^

    SyntaxError: Cannot use import statement outside a module
I’d have thought it’d blown up at
npx tsc
if the settings were till wrong (feel free to correct me if I’m wrong)
e
Try setting the module to “commonjs”
l
Copy code
{
  "compilerOptions": {
    "strict": true,
    "outDir": "bin",
    "target": "es2020",
    "module": "commonjs",
    "moduleResolution": "node",
    "sourceMap": true,
    "experimentalDecorators": true,
    "esModuleInterop": true,
    "resolveJsonModule": true,
    "pretty": true,
    "noFallthroughCasesInSwitch": true,
    "noImplicitReturns": true,
    "forceConsistentCasingInFileNames": true
  }
}
Copy code
{
  "name": "creatio-sync",
  "main": "bin/index.js",
  "devDependencies": {
    "@types/node": "^10.0.0"
  },
  "dependencies": {
    "@devops/pulumi-utils": "^0.1.2",
    "@pulumi/kubernetes": "^2.0.0",
    "@pulumi/kubernetesx": "^0.1.1",
    "@pulumi/pulumi": "^2.0.0"
  }
}
It's a dependency that's causing the issue
feels like I need to cascade the
tsc
call to the library too
Fixed the issue. Turns out my inexperience with TS meant I was packaging a helper as TS and not the transpiled JS