2

I have an existing Blazor project that has target framework set to .NET 6.0. After installing Visual Studio 17.4.1 and setting the target framework to .NET 7.0, I get a runtime error:

Uncaught SyntaxError: Cannot use 'import.meta' outside a module (at dotnet..3611wiw0dy.js:8:27)

enter image description here

What should I set to make it work?

Nestor
  • 8,194
  • 7
  • 77
  • 156
  • Might you please [edit] your question to include your code and errors as **text** rather than as a screenshot? On stack overflow images should not be used for textual content, see [*Why should I not upload images of code/data/errors?*](https://meta.stackoverflow.com/a/285557) and [*Discourage screenshots of code and/or errors*](https://meta.stackoverflow.com/a/307500) for why. A [mcve] showing the code that reproduces the error would be ideal. – dbc Nov 21 '22 at 15:40
  • Please check you do not have any package references still using dotnet 6 and that you have cleared your build cache (delete .vs (if you have one), bin and obj folders) and browser cache completely before rebuilding. – Mister Magoo Nov 21 '22 at 16:08
  • If my personal history serves me anything, is that upgrades are always complicated, and I have yet to read a story of someone fixing these issues without creating a new solution in the new version and importing the project files from the previous one. I hope someone will prove me wrong. See here https://stackoverflow.com/questions/73021062/how-to-convert-blazor-web-assembly-from-net-framework-5-0-to-6-0?rq=1 – Shuryno Nov 21 '22 at 18:54

2 Answers2

1

You may need to upgrade your nuget packages to version 7.0

Eg.:

Microsoft.AspNetCore.Components.WebAssembly
Microsoft.AspNetCore.Components.WebAssembly.DevServer
Microsoft.AspNetCore.Components.Authorization
Microsoft.Extensions
0

This just happened to me and how I solved it is just as Juan has suggested. I had to first of course, switch the version to .Net7.0. Then I upgraded all of the packages to the newest versions (important to note I had a smaller project). Lastly, I had to change the way services are added to the service builder. from the lambda method used in .Net6.0 to one that maps the interface to the implementation.

After this, I had just a few more cleanups to do and that was it for me.

Quite simply explained. hope this works for someone else.

mw509
  • 1,957
  • 1
  • 19
  • 25