Using Pulumi with Typescript, if I make a typo in ...
# general
n
Using Pulumi with Typescript, if I make a typo in some variable name or make some silly syntax mistake I get this obscure error message (regardless of what the problem is) instead of the expected error message pointing to the actual error:
Copy code
TypeError: Cannot convert object to primitive value
        at process.uncaughtHandler (/home/ubuntu/infra/node_modules/@pulumi/cmd/run/run.ts:305:65)
        at process.emit (node:events:531:35)
        at process.emit (/home/ubuntu/infra/node_modules/source-map-support/source-map-support.js:516:21)
        at emit (node:internal/process/promises:150:20)
        at processPromiseRejections (node:internal/process/promises:284:27)
        at processTicksAndRejections (node:internal/process/task_queues:96:32)
any ideas ?
f
👋 can you provide a short snippet/example of a typo you're doing? TS is usually pretty helpful e.g. I misspell my variable `bucket`:
Copy code
index.ts(9,27): error TS2552: Cannot find name 'bucketr'. Did you mean 'bucket'?
b
I have the same issue, it's been happening for a while. I'm using ESM modules to get top-level await (I have this config since 3 years):
Copy code
# Pulumi.yaml
name: proj
description: something
runtime:
  name: nodejs
  options:
    typescript: true
    # See <https://github.com/TypeStrong/ts-node/issues/1007>
    nodeargs: "--loader ts-node/esm --no-warnings"
f
@bland-processor-73185 are you saying this is ESM-specific or?
b
Indeed this seems to be ESM-specific A simple
index.ts
containing just
failll
causes:
Copy code
Previewing update (dev):
     Type                 Name             Plan     Info
     pulumi:pulumi:Stack  toto-dev           2 errors

Diagnostics:
  pulumi:pulumi:Stack (toto-dev):
    error: Running program '/work/pulumi-toto' failed with an unhandled exception:
    TypeError: Cannot convert object to primitive value
        at process.uncaughtHandler (/work/pulumi-toto/node_modules/@pulumi/cmd/run/run.ts:309:65)
        at process.emit (node:events:532:35)
        at process.emit (node:domain:488:12)
        at process.emit.sharedData.processEmitHook.installedValue [as emit] (/work/pulumi-toto/node_modules/@cspotcode/source-map-support/source-map-support.js:745:40)
        at emitUnhandledRejection (node:internal/process/promises:250:13)
        at throwUnhandledRejectionsMode (node:internal/process/promises:385:19)
        at processPromiseRejections (node:internal/process/promises:470:17)
        at processTicksAndRejections (node:internal/process/task_queues:96:32)
    error: an unhandled error occurred: Program exited with non-zero exit code: 1
I solved the issue: basically
ts-node
sucks (issues about ESM are still open after years), just use
tsx
: https://github.com/pulumi/docs/issues/9466#issuecomment-2429480495
Copy code
Previewing update (dev):
     Type                 Name             Plan     Info
     pulumi:pulumi:Stack  toto-dev           1 error; 2 messages

Diagnostics:
  pulumi:pulumi:Stack (toto-dev):
    (node:751473) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
    (Use `node22 --trace-deprecation ...` to show where the warning was created)

    error: Running program '/work/pulumi-toto' failed with an unhandled exception:
    ReferenceError: failll is not defined
        at file:///work/pulumi-toto/index.ts:1:1
        at ModuleJob.run (node:internal/modules/esm/module_job:262:25)
        at async ModuleLoader.import (node:internal/modules/esm/loader:474:24)
103 Views