I have a function inside of a package like this: ...
# typescript
m
I have a function inside of a package like this:
Copy code
import * as gcp from '@pulumi/gcp';
import { asset, interpolate } from '@pulumi/pulumi';

export function createServerlessInvokedVM(opts: ContainerSettings): gcp.cloudfunctions.Function
but when I try to use it in another file then I get an error:
Copy code
pulumi up --refresh
Previewing update (dev)
     Type                 Name            Plan       Info
 +   pulumi:pulumi:Stack  bq-to-asql-dev  create     1 error
 
Diagnostics:
  pulumi:pulumi:Stack (bq-to-asql-dev):
    error: Running program '/home/xk/bera/legacy-product-db/packages/bq-to-mssql/infra' failed with an unhandled exception:
    /home/xk/bera/legacy-product-db/packages/bq-to-mssql/infra/node_modules/.pnpm/@bera/extended-cloud-run@1.0.0/node_modules/@bera/extended-cloud-run/infra/index.ts:1
    import * as gcp from '@pulumi/gcp';
    ^^^^^^
    
    SyntaxError: Cannot use import statement outside a module
        at wrapSafe (internal/modules/cjs/loader.js:1072:16)
        at Module._compile (internal/modules/cjs/loader.js:1122:27)
        at Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
        at Object.require.extensions.<computed> [as .ts] (/home/xk/bera/legacy-product-db/packages/bq-to-mssql/infra/node_modules/.pnpm/ts-node@7.0.1/node_modules/ts-node/src/index.ts:431:14)
        at Module.load (internal/modules/cjs/loader.js:1002:32)
        at Function.Module._load (internal/modules/cjs/loader.js:901:14)
        at Module.require (internal/modules/cjs/loader.js:1044:19)
        at require (internal/modules/cjs/helpers.js:77:18)
        at Object.<anonymous> (/home/xk/bera/legacy-product-db/packages/bq-to-mssql/infra/index.ts:1:1)
        at Module._compile (internal/modules/cjs/loader.js:1158:30)
will Pulumi want a JS file instead of a TS file??
l
No, don't need a JS file. Looks like your Pulumi project hasn't been set up as a module. It has an import statement, that's important (excuse the pun). You also need to configure your package.json properly. You may want to set
Copy code
"type": "module",
 "module": "esnext"
or similar.
partypus 1
👍 1
I'm not too familiar with it, but I found loads of help googling...