There can be n numbera lot of of possibilities for getting, "SyntaxError: Cannot use import statement outside a module "
SyntaxError: Cannot use import statement outside a module
while running typescript.
In my setup, I was importing a module called, AbModule AbModule (AbModuleAbModule has class AbClassNameAbClassName) from my script testabtestab.ts.ts
testab.tstestab.ts had import stmt,
import {AbClassName} = 'testAdapterDir/AbModule.po.ts';import stmt,
import {AbClassName} = 'testAdapterDir/AbModule.po.ts';
However,
AbModule hadAbModule had all *.ts*.ts files and there were *.js*.js files were not present.
fix is,
cd AbModule path
tsc *.ts (you may get errors but ignore them)
You may get errors in running the below code but you can safely ignore them.
cd AbModule path
tsc *.ts
now AbModuleNow AbModule should comtaincontain compiled files all *.js*.js too.
Now run testab.tstestab.ts and noticed that SyntaxError: Cannot use import statement outside a module"the mentioned error does not existsexist anymore,