1

I'me using typescript and cloud functions to build my backend, still very new to typescript. Trying to break down my gigantic index.ts into multiple files

background-job.ts

export const pickWinnerBackgroundJob = functions.pubsub.schedule('every 1 minutes').onRun(async (context) => {

});

index.ts

import * as backgroundJob from './background-job';

exports.evaluateBackgroundJob = backgroundJob.pickWinnerBackgroundJob;

When i try to deploy this i get the following error

src/index.ts:8:39 - error TS2306: File '/Users/name/Desktop/Repos/App/Web/functions/src/background-job.ts' is not a module.

import * as backgroundJob from './background-job';
                                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~

Any idea why it's complaining?

5
  • 2
    In my experience, the "file is not a module" error in otherwise good-looking TypeScript code is that you've got a typo in your TypeScript (or in an import) that makes it TS that can't be compiled. Commented Oct 10, 2020 at 5:09
  • exports.evaluateBackgroundJob looks like CommonJS, but export const pickWinnerBackgroundJob looks like ES6 module syntax. Commented Oct 10, 2020 at 8:03
  • 1
    the problem was I had a const named the same as the imported name, renaming the const fixed the issue
    – aryaxt
    Commented Oct 12, 2020 at 4:11
  • @aryaxt Could you post your fix as an answer so that other community members would benefit from it? Thanks.
    – Katayoon
    Commented Oct 16, 2020 at 17:53
  • I actually had a commented out identical variable name.
    – Roy Falk
    Commented Apr 14, 2022 at 5:35

1 Answer 1

2

the problem was I had a const named the same as the imported name, renaming the const fixed the issue

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.