nanolith
nanolith copied to clipboard
Throwing error "Cannot use import statement outside a module"
I'm using this library within a nextjs application. I have a workers.ts
file which is defined as the following:
import { AppEnvPOAMFindingData, searchAppEnvPoamFindings } from '@repo/shared-api/endpoints/search-app-env-poam-findings';
import { RequestType } from '@repo/shared-api/types/core';
import { exportPoamEventSchema } from '@type/events';
import { define } from 'nanolith';
import 'server-only';
import { z } from 'zod';
export const exportPoamWorker = await define({
async generatePOAMRecords(data: z.infer<typeof exportPoamEventSchema>) {
const { organisationId, applicationId, environmentId } = data;
let currentPage = 1;
const findings: Array<AppEnvPOAMFindingData> = [];
const initialFindings = await searchAppEnvPoamFindings({
organisationId,
applicationId,
environmentId,
page: currentPage,
limit: 1
}, RequestType.Internal);
do {
const pagedFindings = await searchAppEnvPoamFindings({
organisationId,
applicationId,
environmentId,
page: currentPage,
limit: 100
}, RequestType.Internal);
findings.push(...pagedFindings.results);
currentPage = currentPage + 1;
} while(findings.length < initialFindings.totalResults)
return findings;
},
async exportToPOAMTemplateFile(fileName: string, records: Array<AppEnvPOAMFindingData>) {
}
}, {
identifier: 'export-poam-worker',
file: './app/lib/workers.ts',
safeMode: false
})
But when I'm calling the worker, after initialising a service, an error is thrown relating to the import syntax.
"Cannot use import statement outside a module"
I thought TS could be used with this library? Am I doing something wrong here?
Thanks!