Page 1 of 1

Unexpected token < in JSON at position 0 after publish

Posted: Sat Dec 15, 2018 9:42 am
by mrapi
Hi,I'm trying to publish my app (Asp .net core 2.1+Angular 7+stimul 2018.3.5),the report is shown while working in development,but after publish I can't see the report,only got his error in console:
Unexpected token < in JSON at position 0
I've tested also with empty report with just a simple text put in title (report is attached)

the code used:

Code: Select all

declare var Stimulsoft: any;


@Component({
  templateUrl: './fact.component.html',
  styleUrls: ['./fact.component.css'],

  encapsulation: ViewEncapsulation.None
})
export class FactComponent implements OnInit {
  options: any = new Stimulsoft.Viewer.StiViewerOptions();
  viewer: any = new Stimulsoft.Viewer.StiViewer(this.options, 'StiViewer', false);
  report = new Stimulsoft.Report.StiReport();

  ngOnInit() {
   
    this.report.loadFile('./reports/repo.mrt');
    Stimulsoft.Base.Localization.StiLocalization.setLocalizationFile('localization/ro.xml', true);
     this.viewer.report = this.report;
        this.viewer.renderHtml('viewerContent');
    }
localization is loaded also the viewer buttons
after publish I can see files needed for report placed this way:

Code: Select all

/dist/reports/repo.mrt
/dist/localization/ro.xml

angular.json:

Code: Select all

...........
"assets": [
              "src/assets",
	      "src/reports",
     	      "src/localization"
            ],
            "styles": [
          ........
              "src/styles.css",
              "src/stimulsoft/stimulsoft.viewer.office2013.whiteblue.css"
            ],
            "scripts": [
			"src/stimulsoft/stimulsoft.reports.pack.js",
            "src/stimulsoft/stimulsoft.viewer.pack.js"
			]

thanks

Re: Unexpected token < in JSON at position 0 after publish

Posted: Mon Dec 17, 2018 2:28 pm
by Lech Kulikowski
Hello,

Please send us a simple project which reproduces the issue for analysis.

Thank you.

Re: Unexpected token < in JSON at position 0 after publish

Posted: Mon Dec 17, 2018 6:49 pm
by mrapi
Hi,I've attached sample project,and publish files
see fetch-data component
thanks


Image

Re: Unexpected token < in JSON at position 0 after publish

Posted: Fri Dec 21, 2018 3:13 pm
by Lech Kulikowski
Hello,

We tested your example. In this case, your project does not produce the correct result when accessing the report file with the extension. If you change the report extension to .xml, the report starts working correctly. You need to configure your Angular project in such a way that it works correctly with .mrt files, or change the extension to .xml in the report.

Thank you.

Re: Unexpected token < in JSON at position 0 after publish

Posted: Fri Dec 21, 2018 5:26 pm
by mrapi
indeed,renaming it to xml works

I've solved using in .csproj file after build command to rename mrt files to xml:

Code: Select all

<Target Name="GenerateContentFilesAfterPublish" BeforeTargets="AfterPublish">
        <Exec Command="ren $(SolutionDir)bin\Release\PublishOutput\ClientApp\dist\reports\*.mrt *.xml" />
</Target>
then in my angular project I load report files using isDevMode()

Code: Select all

..
 this.report.loadFile(fnGetRepoPath('myreport'));
...
import {  isDevMode } from '@angular/core';
...
 fnGetRepoPath(n: string): string {
    return './reports/' + n + (isDevMode() ? '.mrt' : '.xml');
  }
thanks

Re: Unexpected token < in JSON at position 0 after publish

Posted: Sat Dec 22, 2018 12:33 pm
by Lech Kulikowski
Hello,

Thank you for the information.