https://pulumi.com logo
Title
e

elegant-pager-5412

04/28/2021, 9:32 AM
Or rather, how can I use
target: "es2020"
and compile the project myself, piping the output JS to Pulumi?
b

billowy-army-68599

04/28/2021, 2:50 PM
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
options
  typescript: false
https://www.pulumi.com/docs/reference/pulumi-yaml/
l

lemon-monkey-228

04/28/2021, 3:25 PM
How do we then leverage this to deploy/
Manually compile and
pulumi up
?
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
runtime:
  name: nodejs
  options:
    typescript: false
but still no dice
b

billowy-army-68599

04/28/2021, 3:33 PM
when you say
pulumi up
seems to be trying to use it, do you mean your index.ts ?
e

elegant-pager-5412

04/28/2021, 3:41 PM
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:
"scripts": {
    "deploy": "tsc && sed -i '' \"s#\\\"main\\\": \\\".*,#\\\"main\\\": \\\"$(find dist -name 'index.js' -print -maxdepth 3 -quit)\\\",#\" package.json && pulumi up"
  },
l

lemon-monkey-228

04/28/2021, 3:41 PM
sorry, yeah, and I’m assuming it is
e

elegant-pager-5412

04/28/2021, 3:41 PM
This works for me, I guess the script should be slightly modified for others
my `tsconfig.json`:
{
  "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

lemon-monkey-228

04/28/2021, 3:46 PM
My exact issue is
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

elegant-pager-5412

04/28/2021, 3:51 PM
Try setting the module to “commonjs”
l

lemon-monkey-228

04/28/2021, 4:38 PM
{
  "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
  }
}
{
  "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