hello I cannot resolve path, the path is well regi...
# typescript
p
hello I cannot resolve path, the path is well registered ??
Copy code
cwd /Users/john/Desktop/nxapp/apps/app-web/src-infra
    {
      target: 'es6',
      module: 'commonjs',
      moduleResolution: 'node',
      sourceMap: 'true',
      baseUrl: '../../../',
      paths: {
        '@app/infra': [ 'libs/infra/src/index.ts' ],
      },
      traceResolution: true
    }
 
    error: Running program '/Users/john/Desktop/nxapp/apps/app-web/src-infra/main.ts' failed with an unhandled exception:
    Error: Cannot find module '@app/infra'
    Require stack:
    - /Users/john/Desktop/nxapp/apps/app-web/src-infra/main.ts
    - /Users/john/Desktop/nxapp/node_modules/@pulumi/pulumi/cmd/run/run.js
    - /Users/john/Desktop/nxapp/node_modules/@pulumi/pulumi/cmd/run/index.js
        at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
        at Function.Module._load (node:internal/modules/cjs/loader:778:27)
        at Module.require (node:internal/modules/cjs/loader:1005:19)
        at require (node:internal/modules/cjs/helpers:102:18)
        at Object.<anonymous> (/Users/john/Desktop/nxapp/apps/app-web/src-infra/main.ts:1:1)
        at Module._compile (node:internal/modules/cjs/loader:1101:14)
        at Module.m._compile (/Users/john/Desktop/nxapp/node_modules/@pulumi/pulumi/node_modules/ts-node/src/index.ts:439:23)
        at Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
        at Object.require.extensions.<computed> [as .ts] (/Users/john/Desktop/nxapp/node_modules/@pulumi/pulumi/node_modules/ts-node/src/index.ts:442:12)
        at Module.load (node:internal/modules/cjs/loader:981:32)
b
there isn't enough informatio here I'm afraid, how is your repo laid out?
p
Im using a https://nx.dev/ monorepo I colocated my React App and my Pulumi in the same folder
apps/app-web
and reserved
apps/app-web/src-infra
for pulumi scripts and tsconfig.json I’m trying to load a library of pulumi component resources in
libs/infra
it works with a relative path but not with an absolute path
@app/infra
defined in
tsconfig.json
so
Copy code
apps/app-web/* (react root)
apps/app-web/Pulumi.yaml
apps/app-web/Pulumi.app-web.dev.yaml
apps/app-web/src-infra/main.ts (pulumi script)
apps/app-web/src-infra/tsconfig.json (for pulumi)
libs/infra/src/index.ts (pulumi comp res)
package.json
tsconfig.base.json
I have been able to pass my custom path and baseurl using tsconfig.json in the same folder as my pulumi script. my path are well registered with ts-node and baseurl is correct relative to the script cwd I have printed out this line config: https://github.com/pulumi/pulumi/blob/master/sdk/nodejs/cmd/run/run.ts#L174
Copy code
{
      target: 'es6',
      module: 'commonjs',
      moduleResolution: 'node',
      sourceMap: 'true',
      baseUrl: '../../../',
      paths: {
        '@app/infra': [ 'libs/infra/src/index.ts' ]
      },
      traceResolution: true
    }
it seems like Typescript is finding my import, but I get an error from nodeJS when it tried to load the module
b
sorry I'm not familiar with nx.dev
you do need to run things with the pulumi cli, or use automation API
p
@billowy-army-68599 alright I made it work 🙂 thanks to https://github.com/pulumi/pulumi/issues/3061#issuecomment-822501184
❤️ 1
thank you