TS1208

error TS1208: ‘index.ts’ cannot be compiled under ‘–isolatedModules’ because it is considered a global script file. Add an import, export, or an empty ‘export {}’ statement to make it a module.

Bad Code ❌

tsconfig.json

1
2
3
4
5
{
"compilerOptions": {
"isolatedModules": true
}
}

index.ts

1
2
3
require(`dotenv-defaults`).config({
path: '.env',
});

Fixed Code ✔️

To solve the issue you can turn off isolatedModules in your tsconfig.json. If you want to keep going with isolated modules, then you have to add an import or export to your code:

index.ts

1
2
3
4
5
require(`dotenv-defaults`).config({
path: '.env',
});

export default {};