Currently, I am in the process of developing an Angular 4 theme specifically designed for Wordpress 4.8, intended to function seamlessly on Edge and Chrome browsers. During my testing phase, I encountered an issue with my test script (test.ts) which resulted in the following error:
Uncaught SyntaxError: Unexpected token import at src/test.js:1
For reference, here is the content of my tsconfig.json file located within the \src folder:
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [ "es2016", "es5", "dom"],
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true
}
}
In addition, here is the configuration of tsconfig.json present at the root level:
{
"compileOnSave": false,
"compilerOptions": {
"outDir": "./dist/out-tsc",
"baseUrl": "src",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2016",
"dom",
"es5"
]
}
}
The contents of my test.ts file are as follows:
import {BrowserDynamicTestingModule, platformBrowserDynamicTesting} from
"@angular/platform-browser-dynamic/testing";
import {getTestBed} from "@angular/core/testing";
declare var _karma_: any;
declare var require: any;
_karma_.loaded = function () {};
getTestBed().initTestEnvironment(
BrowserDynamicTestingModule,
platformBrowserDynamicTesting()
);
const context = require.context('./', true, /\.spec\.ts$/);
context.keys().map(context);
_karma_.start();
I am seeking advice on the optimal method to address this error. Any suggestions would be greatly appreciated.