I’ve been trying to update an Angular2 project to a more recent version of Angular. Currently it’s using Angular 15.2.10 and I’ve gone through a number of errors already but this one is proving difficult to resolve. The application builds successfully but the browser console is giving an error where it’s not transpiling @angular/browser-platform and I’m not sure why.
I’ve already looked at adding “plugin-babel” as a transpiler in systemjs.config.js but that then gives a completely different error regarding a nullish coalescing operator in @angular/common/http.
Console error (@angular/platform-browser)
Unable to load transpiler to transpile http://localhost:3000/node_modules/@angular/platform-browser/esm2020/index.mjs
Console error (@angular/common/http)
(index):72
(SystemJS) http://localhost:3000/node_modules/@angular/common/esm2020/http/src/interceptor.mjs: Unexpected token (52:80)
50 | return (req, handler) => {
51 | if (chain === null) {
> 52 | const interceptors = inject(HTTP_INTERCEPTORS, { optional: true }) ?? [];
| ^
53 | // Note: interceptors are wrapped right-to-left so that final execution order is
54 | // left-to-right. That is, if `interceptors` is the array `[a, b, c]`, we want to
55 | // produce a chain that is conceptually `c(b(a(end)))`, which we build from the inside
SyntaxError: Unexpected token (52:80)
systemjs.config.js
(function(global) {
// map tells the System loader where to look for things
var map = {
'app': 'app', // 'dist',
'@angular': 'node_modules/@angular',
'@angular/common/http': 'node_modules/@angular/common/esm2020/http',
'@angular/common/esm2020/src/directives/ng_optimized_image': 'node_modules/@angular/common/esm2020/src/directives/ng_optimized_image',
'node-uuid': 'node_modules/node-uuid',
'ngx-bootstrap': 'node_modules/ngx-bootstrap',
'rxjs': 'node_modules/rxjs',
'rxjs/operators': 'node_modules/rxjs',
'moment': 'node_modules/moment/moment.js',
'dragula': 'node_modules/dragula/dist/dragula.min.js',
'ng2-dragula': 'node_modules/ng2-dragula',
'angular2-highcharts': 'node_modules/angular2-highcharts',
'highcharts': 'node_modules/highcharts',
'highcharts/highstock.src': 'node_modules/highcharts/highstock.js',
'plugin-babel': 'node_modules/systemjs-plugin-babel/plugin-babel.js',
'systemjs-babel-build': 'node_modules/systemjs-plugin-babel/systemjs-babel-browser.js',
'tslib': 'node_modules/tslib/tslib.js',
'zone.js': 'node_modules/zone.js/bundles/zone.umd.js'
};
// packages tells the System loader how to load when no filename and/or no extension
var packages = {
'app': { main: 'main.js', defaultExtension: 'js' },
'@angular/common/http': { main: 'index.mjs', defaultExtension: 'mjs' },
'@angular/common/esm2020/src/directives/ng_optimized_image': { main: 'index.mjs', defaultExtension: 'mjs' },
'rxjs': { main: 'dist/cjs/index.js', defaultExtension: 'js' },
'rxjs/operators': { main: 'dist/cjs/index.js', defaultExtension: 'js' },
'ngx-bootstrap': { main: 'esm2020/index.mjs', defaultExtension: 'mjs' },
'ngx-bootstrap/modal': { main: 'esm2020/index.mjs', defaultExtension: 'mjs' },
'dragula': { defaultExtension: 'js' },
'ng2-dragula': { defaultExtension: 'mjs', main: 'esm2020/ng2-dragula.mjs' },
'node-uuid': { main: 'uuid.js', defaultExtension: 'js'},
'angular2-highcharts': { main: 'index.js', defaultExtension: 'js'},
'highcharts': { main: 'highcharts.js', defaultExtension: 'js'},
};
var ngPackageNames = [
'common',
'compiler',
'core',
'forms',
'platform-browser',
'platform-browser-dynamic',
'router',
'upgrade',
];
// Individual files (~300 requests):
function packIndex(pkgName) {
packages['@angular/'+pkgName] = { main: 'esm2020/index.mjs', defaultExtension: 'mjs' };
}
// Add package entries for angular packages
ngPackageNames.forEach(packIndex);
var bsPackageNames = [
'modal',
'utils',
'component-loader',
'positioning',
'focus-trap'
];
function bsIndex(pkgName) {
packages['ngx-bootstrap/'+pkgName] = { main: 'esm2020/index.mjs', defaultExtension: 'mjs' };
}
// Add package entries for angular packages
bsPackageNames.forEach(bsIndex);
var config = {
map: map,
packages: packages,
paths: {
'ng2-dragula/*': 'node_modules/ng2-dragula/',
},
//transpiler: 'plugin-babel',
};
System.config(config);
})(this);
ts.config.json
{
"compilerOptions": {
"target": "ES2020",
"module": "System",
"moduleResolution": "node",
"lib": [
"dom",
"ES2020"
],
"sourceMap": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false,
"typeRoots": [
"node_modules/@types"
],
"types": [
"node",
"jasmine",
"jQuery",
"core-js"
],
"useDefineForClassFields": false
},
"exclude": [
"node_modules",
"typings/main",
"typings/main.d.ts"
]
}
package.json
{
"name": "", // Name removed for privacy
"version": "1.0.0",
"scripts": {
"start": "tsc && sass assets/scss/main.scss:assets/css/main.min.css --style compressed && concurrently "npm run tsc:w" "npm run lite" ",
"tsc": "tsc",
"tsc:w": "tsc -w",
"dev": "node ./development.js",
"lite": "lite-server"
},
"license": "ISC",
"dependencies": {
"@angular/animations": "^15.2.10",
"@angular/cli": "^15.2.11",
"@angular/common": "^15.2.10",
"@angular/compiler": "^15.2.10",
"@angular/compiler-cli": "^15.2.10",
"@angular/core": "^15.2.10",
"@angular/forms": "^15.2.10",
"@angular/localize": "^18.1.1",
"@angular/platform-browser": "^15.2.10",
"@angular/platform-browser-dynamic": "^15.2.10",
"@angular/platform-server": "^15.2.10",
"@angular/router": "^15.2.10",
"@angular/upgrade": "^15.2.10",
"@types/core-js": "^2.5.8",
"@types/jasmine": "^2.8.8",
"@types/jquery": "^2.0.42",
"@types/node": "^20.14.11",
"angular2-highcharts": "0.2.1",
"bootstrap": "^3.3.6",
"bootstrap-datepicker": "^1.6.1",
"core-js": "^2.4.0",
"dragula": "^3.7.1",
"hammerjs": "^2.0.8",
"jquery": "^2.2.4",
"moment": "2.0.0",
"ng2-dragula": "^3.2.0",
"ng2-select": "^1.0.3",
"ngx-bootstrap": "^9.0.0",
"node-uuid": "^1.4.7",
"reflect-metadata": "^0.1.3",
"rxjs": "^7.4.0",
"systemjs": "^0.19.42",
"systemjs-plugin-babel": "^0.0.25",
"tinymce": "4.3.12",
"tslib": "^2.0.0",
"typescript": "^4.9.5",
"zone.js": "^0.14.0"
},
"devDependencies": {
"babel-core": "^6.10.4",
"codelyzer": "0.0.23",
"colors": "1.4.0",
"concurrently": "^2.0.0",
"connect": "^3.4.1",
"gulp": "^3.9.1",
"gulp-clean-css": "^2.0.11",
"gulp-concat": "^2.6.0",
"gulp-exec": "^2.1.2",
"gulp-minify": "^0.0.12",
"gulp-nodemon": "^2.1.0",
"gulp-rename": "^1.2.2",
"gulp-rev": "^7.1.0",
"gulp-sourcemaps": "^1.6.0",
"gulp-usemin": "^0.3.23",
"lite-server": "^2.2.0",
"serve-static": "^1.11.1",
"systemjs-builder": "^0.15.23",
"tslint": "^6.0.0"
}
}
Any help would be appreciated 🙂