question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Uncaught SyntaxError: import.meta may only appear in a module

See original GitHub issue

When a server-client project created from the Bolero template (latest) is updated from net6.0 to net7.0, the following error appears in browsers. The Bolero page is also blank, except for the dark Bulma bar with logo at the top which is served by the server-side early, I believe before WebAssembly kicks in.

Firefox: Uncaught SyntaxError: import.meta may only appear in a module source: dotnet.7.0.0.amub20uvka.js

Chrome and Edge: Uncaught SyntaxError: Cannot use ‘import.meta’ outside a module source: some other js-file with a cryptic name

It’s actually the same error, just with slightly different wording, and Firefox is also kind enough to hint about the platform version, which is important here.

How to reproduce:

Run the following web application generated with the latest Bolero template in Visual Studio 17.4.0, currently latest. Also fails in latest Preview version.

HelloWorld.zip

Note that the page is blank, except for the dark Bulma bar with logo at the top.

In a Firefox browser, inspect the page errors using the browser’s developer tools. Note that the name of the failing file indicates this is dotnet7.0.0

To verify that it works with net6.0, change the target in the client to net6.0. That’s all that is needed for success, though the Microsoft assembly can also be downgraded for good measure. Now run with Firefox again, and note that now there is a javascript file name containing dotnet6.0.11, or whichever version of 6.0.x is on the machine.

Observed on two out of two developer machines so far.

This is a continuation of the problem solving in https://github.com/fsbolero/Bolero/issues/279, related to updating to .NET 7. This is a second issue. The first issue was resolved through the use of ProduceReferenceAssembly with value false in client project files.

Additional information. These two log files are the outputs from the console when running net6 and net7. I am not much of an expert here, but I’m guessing there’s not much to gain from studying these, except that net7 doesn’t deliver the missing content.

lognet7b.txt lognet6b.txt

Of course you can test with browsers other than Firefox, but you’ll miss the nice version indication in the WebAssembly javascript filename.

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
Tarmilcommented, Feb 21, 2023

Bolero 0.21.25 should now be working without an explicit dependency on Microsoft.AspNetCore.Components.WebAssembly.

1reaction
Tarmilcommented, Feb 18, 2023

There is now an explicit reference to Microsoft.AspNetCore.Components.WebAssembly 7.0.* in v0.21 of the project template.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Uncaught SyntaxError: Cannot use 'import.meta' outside a ...
meta cannot be used outside of a module, and the script that is coming from is styles.js. It's a known error output, but...
Read more >
Syntaxerror: cannot use 'import.meta' outside a module
meta' in a place where it's not allowed. Also, this error is triggered when the JavaScript file is not being imported as a...
Read more >
Migration from 6 to 7 gives Uncaught SyntaxError: import. ...
Migration from 6 to 7 gives Uncaught SyntaxError: import.meta may only appear in a module #44996 ; area-blazor Includes: Blazor, Razor Components ...
Read more >
Cannot use import statement outside a module
In this quick guide we'll look at how you can solve the very common error, "Uncaught SyntaxError: Cannot use import statement outside a ......
Read more >
Fix - Cannot use import statement outside module in JS or ...
Sometimes, the error is presented as 'Uncaught SyntaxError: import declarations may only appear at top level of a module' instead of what is ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found