SynaxError: Unexpected Token export

I am trying to run my code that imports some types from "@cloudflare/workers-types" but it gives me this error
/home/----/----/node_modules/.pnpm/@cloudflare+workers-types@4.20240314.0/node_modules/@cloudflare/workers-types/index.ts:17

export declare class DOMException extends Error {
^^^^^^

SyntaxError: Unexpected token 'export'
/home/----/----/node_modules/.pnpm/@cloudflare+workers-types@4.20240314.0/node_modules/@cloudflare/workers-types/index.ts:17

export declare class DOMException extends Error {
^^^^^^

SyntaxError: Unexpected token 'export'
Its a monorepo and am using simple ts-node to run my index file. This file imports a local package that in turn imports from "cloudflare/workers-types".
3 Replies
DaniFoldi
DaniFoldi3mo ago
Could it be that you're missing "type": "module" from your package.json? I think ts-node defaults to cjs if type is not explicitly declared, and esm imports/exports don't work there
fero.xd
fero.xd3mo ago
nvm i fixed it i didnt need to import them adding "types": ["@cloudflare/workers-types"] did that on a global level
DaniFoldi
DaniFoldi3mo ago
yup, for most use cases you should be fine with that, although I recommend using a "newer" entrypoint the default one points to the oldest date, if you check here https://www.npmjs.com/package/@cloudflare/workers-types#compatibility-dates I recommend appending the date that is the newest out of those still older than your specified compatibility date