2

I have a project in angularjs that i want to upgrade. So i installed ng-upgrade and got it set up, but when i ran the program i got this error:

Uncaught SyntaxError: Unexpected token ! vendors.bundle.js 174

I am new to webpack, what should i do?

I don't understand the problem and nobody seems to have encountered it before me. I haven't changed anything in webpack.config.js, just installed everything so i have no idea how it changed vendors.bundle.js.

Here ar my ts loader configuration in webpack.config.js

rules: [
    {
        test: /\.tsx?$/,
        loader: "awesome-typescript-loader"
    },
    {
        test: /\.js$/,
        enforce: "pre",
        loader: "source-map-loader"
    },

Main.ts:

import 'zone.js';
import 'reflect-metadata';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

import { setAngularLib } from '@angular/upgrade/static';
import * as angular from 'angular';

import { AppModule } from './app.module';

setAngularLib(angular);
platformBrowserDynamic().bootstrapModule(AppModule);

app.module.ts:

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { UpgradeModule } from '@angular/upgrade/static';

@ngModule({
    imports: [
        BrowserModule,
        UpgradeModule
    ]
})
export class AppModule {
    constructor(private upgrade: UpgradeModule) {}

    ngDoBootstrap() {
        this.upgrade.bootstrap(document.documentElement, ["spp"], {strictDi: true});
    }
}

Icant seem to find any problems with the code, so i expect it to just show the thml.

Nicholas
  • 41
  • 9
  • This probably isn't your problem, but you have a comma on an otherwise blank line in Main.ts – Collierre Sep 07 '19 at 10:10
  • Ok, so is there any way to get rid of the ! then? – Nicholas Sep 07 '19 at 10:54
  • Can you look in `vendors.bundle.js` line 174 and see where the exclamation mark is? You should remove the comma from Main.ts - if you post broken code here it's harder to help you. – Collierre Sep 07 '19 at 12:01
  • The line looks like this: `var LOCATION_INITIALIZED = new !(function webpackMissingModule() { var e = new Error("Cannot find module '@angular/core'"); e.code = 'MODULE_NOT_FOUND'; throw e; }())('Location Initialized');` – Nicholas Sep 08 '19 at 05:58
  • Hhm that is strange. I'd think that that code shouldn't include the `new` keyword and that it would work without it, as it seems to be trying to use this syntax: https://stackoverflow.com/questions/3755606/what-does-the-exclamation-mark-do-before-the-function I'd be interested to know if this works without `new`. However as it's a bundle file this won't solve your problem, and I'm not sure why the `new` is being added. – Collierre Sep 08 '19 at 11:55
  • It worked fine before and i did not change anything in `webpack.config.js`, so why did the error occure in the first place? – Nicholas Sep 08 '19 at 12:26

1 Answers1

0

i accidently installed @angular/core before its dependencies so didn't install, to fix this i just had to reinstall @angular/core.

Nicholas
  • 41
  • 9