Syntax error in Angular App: Unexpected token <

I have an Angular app that works fine in my local and production environment. After a small change I made, I ran the application locally and it works great. Then I built the project and copied the dist folder to the web server. The problem is that when I try to access the application, I get the following error in Chrome Inspector:

Uncaught SyntaxError: Unexpected token < inline.1a152b6….bundle.js:1
Uncaught SyntaxError: Unexpected token < polyfills.1553fdd….bundle.js:1
Uncaught SyntaxError: Unexpected token < vendor.94d0113….bundle.js:1
Uncaught SyntaxError: Unexpected token < main.d6f56a1….bundle.js:1

So, it looks like this is a non-local character, but in my local environment the application works fine, I do not get a warning or error message on the console.

+35
source share
20 answers

, 404 , html JavaScript. (HTML- <html> <!DOCTYPE...>)

, . , URL- , , .

+21

:

1)

ng build --aot --prod

2)

3) FTP (FileZilla) Windows Azure.

4)

Unexpected token <

, [hash].js Filezilla .

. . , .

:

ng  build --aot --prod --output-hashing none

.

, Filezilla, Windows Server .

+8

, .

, , " dist/the-app ", " dist ", .

// Point static path to dist
app.use(express.static(path.join(__dirname, 'dist/the-app')));

- .

+4

Angular, , , , , , , - , index.html : <base href="./">, . : <base href="/">.

+3

dist/{yourProjectName}/ <base href="/"> index.html, , angular dist/{yourProjectName}/ index.html dist/ for . 2 :

  1. <base href="/"> index.html <base href="/dist/{yourProjectName}/"> ng serve ng build ng serve. , !

  2. , , ! angular.json "outputPath": "dist/{yourProjcetName}", "outputPath": "dist/" base href !

+2

, . , Apache .htaccess , RewriteBase. <base href=""> .

app.use(express.static(__dirname + '/dist'));

app.get.

, dist.

+1

<!--...-->

+1

<base href="/"> <base href="/project-app/"> index.html.

+1

/ , .

:

/myProject

0

webapi angular, ,

    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }

        //For angular url rewriting
        app.Use(async (context, next) =>
        {
            await next();
            if (context.Response.StatusCode == 404 && !Path.HasExtension(context.Request.Path.Value))
            {
                context.Request.Path = "/index.html";
                await next();
            }
        })
        .UseDefaultFiles(new DefaultFilesOptions { DefaultFileNames = new List<string> { "index.html" } })
        .UseStaticFiles();

        app.UseAuthentication();

        app.UseMvc();
    }
0

, wwwroot, asp.net.

:

wwwroot
      |--> assets 
                  |---> ckeditor

angular → src → assets

Uncaught SyntaxError: Unexpected token < inline.1a152b6….bundle.js:1
...
0

, . , , .

Application Settings Azure -

: WEBSITE_NODE_DEFAULT_VERSION : 6.9.1

> - .

remote: The package.json file does not specify node.js engine version constraints.
remote: The node.js application will run with the default node.js version 0.10.40.
remote: Selected npm version 1.4.28


remote: The package.json file does not specify node.js engine version constraints.
remote: The node.js application will run with the default node.js version 6.9.1.
remote: Selected npm version 3.10.8

screen capture from azure portal

0

.htaccess .

https://angular.io/guide/deployment#fallback :

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.html
0

UTF-8.

:

<component [inputField]="Artikelns Mått"></component>

å a. .

, '' .

<component [inputField]="'Artikelns Mått'"></component>

:

Error: Template parse errors:
Parser Error: Unexpected token 'å' at column 11 in [Artikelns mått] in [email protected]:28 ("
    <div class="col-md-4">
        <lte-box>
            <lte-box-header [ERROR ->][headerTitle]="Artikelns mått"></lte-box-header>
            <lte-box-body>
                <table "): [email protected]:28
Parser Error: Lexer Error: Unexpected character [å] at column 12 in expression [Artikelns mått] at column 13 in [Artikelns mått] in [email protected]:28 ("
    <div class="col-md-4">
        <lte-box>
            <lte-box-header [ERROR ->][headerTitle]="Artikelns mått"></lte-box-header>
            <lte-box-body>
                <table "): [email protected]:28
    at SyntaxError.BaseError [as constructor] (webpack:///./@angular/compiler/src/facade/errors.js?:31:27) [<root>]
    at new SyntaxError (webpack:///./@angular/compiler/src/util.js?:163:16) [<root>]
    at TemplateParser.parse (webpack:///./@angular/compiler/src/template_parser/template_parser.js?:170:19) [<root>]
    at JitCompiler._compileTemplate (webpack:///./@angular/compiler/src/jit/compiler.js?:381:68) [<root>]
    at eval (webpack:///./@angular/compiler/src/jit/compiler.js?:264:62) [<root>]
    at Set.forEach (<anonymous>) [<root>]
    at JitCompiler._compileComponents (webpack:///./@angular/compiler/src/jit/compiler.js?:264:19) [<root>]
    at createResult (webpack:///./@angular/compiler/src/jit/compiler.js?:146:19) [<root>]
    at Zone.run (webpack:///./zone.js/dist/zone.js?:112:43) [<root> => <root>]
    at eval (webpack:///./zone.js/dist/zone.js?:534:57) [<root>]
    at Zone.runTask (webpack:///./zone.js/dist/zone.js?:150:47) [<root> => <root>]
    at drainMicroTaskQueue (webpack:///./zone.js/dist/zone.js?:432:35) [<root>]
0

, ( ) . ng build.

0

, , . , , Jhipster, Google Analytics index.html. . index.html script.

, - Google Analytics.

, :

<script>
        (function (b, o, i, l, e, r) {
            b.GoogleAnalyticsObject = l;
            b[l] || (b[l] =
                function () {
                    (b[l].q = b[l].q || []).push(arguments)
                });
            b[l].l = +new Date;
            e = o.createElement(i);
            r = o.getElementsByTagName(i)[0];
            e.src = '//www.google-analytics.com/analytics.js';
            r.parentNode.insertBefore(e, r)
        }(window, document, 'script', 'ga'));
        ga('create', '123123'); <! --
        ga('send', 'pageview');
        -->

    </script>

, <! -- <! --. .

index.html, , \\ . , - , <!-- -->.

, .
index.html

, .

0

, , app.use(express.static ( )) , unexpected token < .

, app.use(express.static(static folder)) , js css , .

Angular (ng build --prod) Angular ng build --prod dist, , (, ), .

(ng build --prod) /dist . , angular.json "outputPath": "dist" , , Angular. server.js, , , app.js, app.use(express.static(static folder)) /backend. , js css unexpected token < error:

  app.use(express.static(path.join('dist')));

  app.use(express.static(path.join(__dirname, '../dist')));

js css /dist.

0

, .

, . URL-, index.html, Angular .

, http://example.com/some-angular-route/12345

, URL (http://example.com/some-angular-route/runtime.js)

, nginx /some-angular-route/runtime.js, index.html, try_files ( nginx) $ uri , , index. HTML. , :

  • index.html , http://example.com/some-angular-route/runtime.js
  • nginx index.html,
  • runtime.js index.html, <html>
  • , Uncaught SyntaxError: Unexpected token <

, /some-angular-route/ URL runtime.js? , base-href /. --base-href=/

index.html . URL-, some-angular-route, , runtime.js ( URL-) /.

0
<meta http-equiv="Cache-control" content="no-cache, no-store, must-revalidate">
<meta http-equiv="Pragma" content="no-cache">

index.html

: Chrome index.html, main.hash.js , " <".

-1

, index.html

<base href="/">

<base href=".">
-1
source

All Articles