0

I would like to add some javascript libraries to my reactJS project.

I do this by adding script tags to the section of index.html

<script src="../src/components/reports/scripts/stimulsoft.reports.js"></script>
<script src="../src/components/reports/scripts/stimulsoft.viewer.js"></script>

and usage of library is like:

class Viewer extends React.Component {
        render() {
            return <div id="viewerContent"></div>;
        }

        componentWillMount() {
            var report = Stimulsoft.Report.StiReport.createNewReport();
            report.loadFile("reports/Report.mrt");

            var options = new Stimulsoft.Viewer.StiViewerOptions();
            this.viewer = new Stimulsoft.Viewer.StiViewer(options, "StiViewer", false);
            this.viewer.report = report;
        }

        componentDidMount() {
            this.viewer.renderHtml("viewerContent");
        }
    }

but I have this error: enter image description here

these are original sample Stimulsoft Reports.JS and GitHub

6
  • componentWillMount for all practical purposes has been deprecated, have you tried using componentDidMount fully instead? I suspect you are calling that code and it may not be fully loaded yet... just guessing at this point though. Commented Nov 17, 2020 at 7:58
  • 1
    window doesnot have a Simulsoft object attached. May be because the Simulsoft JS files are not accessible/invoked from index.html which is available in public folder. Commented Nov 17, 2020 at 8:05
  • Thanks for your reply, @Drew . I tested it (using componentDidMount), but still problem exist. Commented Nov 17, 2020 at 8:11
  • 1
    The error message doesn't match the code. Anyway this has nothing to do with React – the Stimulsoft scripts just haven't loaded (or are broken.) Check the console's network tab and confirm that the scripts load correctly. Unless you have some strange setup, the browser can't access the src directory. Commented Nov 17, 2020 at 8:19
  • If you are using the GitHub sample as reference, the only think I can suggest, as well as to move your code to the componentDidmount cycle as suggested by @DrewReese, is to make sure that the paths to the stimulsoft scripts are correct, and check that they are loaded, can you share the complete html? Commented Nov 17, 2020 at 8:26

1 Answer 1

1

Based on comments under the question, and the guides presented in index.html file of react project as follows:

//Notice the use of %PUBLIC_URL% in the tags above.
//It will be replaced with the URL of the `public` folder during the build.
//Only files inside the `public` folder can be referenced from the HTML.

I placed scripts folder into the public folder of react project and edit src attribute to new source address, and my problem was solved

and this code work for me:

 <script src="%PUBLIC_URL%/StimulSoft/scripts/stimulsoft.reports.js"></script>
 <script src="%PUBLIC_URL%/StimulSoft/scripts/stimulsoft.viewer.js"></script>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.