erossini / BlazorChartjs

Creates beautiful charts in Blazor using Chart.js. Library for NET6, NET7 and NET8. Source code and demo available.
https://www.puresourcecode.com/dotnet/blazor/blazor-component-for-chartjs/
MIT License
116 stars 44 forks source link

SyntaxError - Chart.js:46 #40

Closed gmlloves closed 1 year ago

gmlloves commented 1 year ago

Hello,

I get this error on startup: Uncaught SyntaxError: export declarations may only appear at top level of a module Chart.js:46 Can you see it?

Thank you, Gaston.

erossini commented 1 year ago

Yes, I saw this message. It is related to this line where there is the word export function. If I remove the export the script is not working.

I don't know why this is a syntax error.

gmlloves commented 1 year ago

It happens because the export directive is for modules and not for plain Javascript.

Add at the end of the page the following scripts:

<script src="_content/PSC.Blazor.Components.Chartjs/lib/Chart.js/chart.js"></script>
<script src="_content/PSC.Blazor.Components.Chartjs/Chart.js"></script>

The is imported from:

      public ChartJsInterop(IJSRuntime jsRuntime)
        {
            moduleTask = new(() => jsRuntime.InvokeAsync<IJSObjectReference>("import",
                "./_content/PSC.Blazor.Components.Chartjs/Chart.js").AsTask());
        }

I removed it from my index.html and the error does not happen anymore (It works for me).

erossini commented 1 year ago

Thank you so much!

Ryan-ECPPro commented 1 year ago

Hi,

We are still seeing the same error on line 46 using version:

Was @gmlloves suggestion above incorporated in a later release or I am missing something in the suggested change.

Thanks

skotl commented 1 year ago

Confirm this issue still exists, albeit it displays as Uncaught SyntaxError: Unexpected token 'export' (at Chart.js:46:1)

Removing the second script src=... from index.html, as described by @gmlloves above, addresses it.

Not sure whether this issue can be reopened, @erossini? Looks like just the readme.md needs to be changed...

Ryan-ECPPro commented 1 year ago

Hi,

I can confirm removing the second line works perfectly.

Thank you @skotl, and thank you @erossini for providing the wrapper!!

erossini commented 1 year ago

Thank you @skotl and @Ryan-ECPPro I'm working on a new version of the components with more functionalities. Hopefully soon, few improvements.

grofit commented 1 year ago

I have tried removing the 2nd line but for some reason the first time it loads it always seems to fail then when I refresh it works as expected.

Either way I am not sure if this bug should be classed as closed as its not fixed in the latest release and requires a manual workaround, are you able to issue a hotfix for this and do a larger release with all your other changes further down the line?