Unexpected token < in JSON at position 0 after publish

Stimulsoft Reports.JS discussion
Post Reply
mrapi
Posts: 282
Joined: Sat Dec 20, 2008 1:08 am

Unexpected token < in JSON at position 0 after publish

Post 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
Attachments
repo.zip
(1.31 KiB) Downloaded 297 times
Lech Kulikowski
Posts: 7291
Joined: Tue Mar 20, 2018 5:34 am

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

Post by Lech Kulikowski »

Hello,

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

Thank you.
mrapi
Posts: 282
Joined: Sat Dec 20, 2008 1:08 am

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

Post by mrapi »

Hi,I've attached sample project,and publish files
see fetch-data component
thanks


Image
Attachments
test_app.zip
(3.49 MiB) Downloaded 308 times
publish.zip
(1.79 MiB) Downloaded 263 times
Lech Kulikowski
Posts: 7291
Joined: Tue Mar 20, 2018 5:34 am

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

Post 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.
mrapi
Posts: 282
Joined: Sat Dec 20, 2008 1:08 am

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

Post 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
Lech Kulikowski
Posts: 7291
Joined: Tue Mar 20, 2018 5:34 am

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

Post by Lech Kulikowski »

Hello,

Thank you for the information.
Post Reply