https://pulumi.com logo
#typescript
Title
# typescript
b

breezy-butcher-78604

12/23/2021, 3:18 AM
does anyone have any experience importing json files in pulumi projects? I’m using AJV to do some config validation and have the following code:
Copy code
import * as pulumi from '@pulumi/pulumi';
import Ajv, { JTDDataType } from 'ajv/dist/jtd';
import repoConfigSchema from './config-schema.json';

// ...
however when running the program with
pulumi up
i get the following error:
Copy code
pulumi:pulumi:Stack (gh-repos-main):
    error: Running program '<redacted>/src' failed with an unhandled exception:
    TSError: ⨯ Unable to compile TypeScript:
    config.ts(3,30): error TS2732: Cannot find module './config-schema.json'. Consider using '--resolveJsonModule' to import module with '.json' extension.

        at createTSError (<redacted>/node_modules/ts-node/src/index.ts:261:12)
        at getOutput (<redacted>/node_modules/ts-node/src/index.ts:367:40)
        at Object.compile (<redacted>/node_modules/ts-node/src/index.ts:558:11)
        at Module.m._compile (<redacted>/node_modules/ts-node/src/index.ts:439:43)
        at Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
        at Object.require.extensions.<computed> [as .ts] (<redacted>/node_modules/ts-node/src/index.ts:442:12)
        at Module.load (internal/modules/cjs/loader.js:950:32)
        at Function.Module._load (internal/modules/cjs/loader.js:790:14)
        at Module.require (internal/modules/cjs/loader.js:974:19)
        at require (internal/modules/cjs/helpers.js:92:18)
but i have enabled
resolveJsonModule
in my tsconfig:
Copy code
{
  "$schema": "<https://json.schemastore.org/tsconfig>",
  "display": "Node 14",
  "compilerOptions": {
    "target": "es2020",
    "lib": [
      "es2020"
    ],
    "module": "commonjs",
    "outDir": "dist/",
    "strict": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true,
    "resolveJsonModule": true
  },
  "include": [
    "src/**/*.ts",
    "src/**/*.json"
  ]
}
any ideas what I’m missing?
f

faint-van-25343

12/23/2021, 3:58 PM
You might need
"moduleResolution": "node",
?
b

breezy-butcher-78604

12/24/2021, 2:51 AM
that didn't help, but i found the problem is related to me changing the
main
property in
Pulumi.yaml
. it seems to mess with module resolution in certain cases, this being one of them
5 Views