How do you import from the `shared` CloudCode task in a TypeScript CloudCode task

Hi,

I am trying to import a file from the shared CloudCode task into a TypeScript CloudCode task.

Import code:
import shared from '../shared/index.js'

I keep on getting the following error:

Error: error TS5055: Cannot write file '/tmp/cloudcode-build/dist/app/cloudcode/shared/index.js' because it would overwrite input file.
    at Object.buildTypescript (/var/task/node_modules/@journeyapps/cloudcode-build/src/build.ts:11:11)
    at Object.buildTask (/var/task/node_modules/@journeyapps/cloudcode-build/src/index.ts:28:9)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at Object.build (/var/task/src/build.ts:221:7)
    at Object.handle (/var/task/src/index.ts:28:19)
    at Runtime.exports.handler (/var/task/src/entry.ts:7:10)

I suspect this could only be fixed from the tsconfig.json file. Am I able to overwrite that file, or is this something that needs to be fixed on a platform level?

This is a limitation in the current CloudCode TypeScript build system.

To work around it, use require instead of import :

const shared = require('../shared');

1 Like