Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Top-level await in fs.js when building for browser environment #14

Closed
M0ns1gn0r opened this issue Sep 13, 2024 · 8 comments
Closed

Top-level await in fs.js when building for browser environment #14

M0ns1gn0r opened this issue Sep 13, 2024 · 8 comments
Assignees
Labels
bug Something isn't working

Comments

@M0ns1gn0r
Copy link

I added logtape to an Angular app. When I start ng serve and open the web page I get the error:

 [ERROR] Top-level await is not available in the configured target environment ("chrome121.0", "edge121.0", "firefox115.0", "ios16.0", "safari16.0" + 7 overrides)

    node_modules/@logtape/logtape/esm/fs.js:10:9:
      10 │     fs = await import("node" + ":fs");
         ╵          ~~~~~

[redacted]\ClientApp\node_modules\vite\node_modules\esbuild\lib\main.js:1651
  let error = new Error(text);
              ^

Error: Build failed with 1 error:
node_modules/@logtape/logtape/esm/fs.js:10:9: ERROR: Top-level await is not available in the configured target environment ("chrome121.0", "edge121.0", "firefox115.0", "ios16.0", "safari16.0" + 7 overrides)
    at failureErrorWithLog ([redacted]\ClientApp\node_modules\vite\node_modules\esbuild\lib\main.js:1651:15)
    at [redacted]\node_modules\vite\node_modules\esbuild\lib\main.js:1059:25
    at [redacted]\node_modules\vite\node_modules\esbuild\lib\main.js:1527:9
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  errors: [Getter/Setter],
  warnings: [Getter/Setter]
}

Node.js v20.11.0

It's unclear to me why fs.js wants to load at all for the browser environment. Could help me to fix the problem?

@dahlia
Copy link
Owner

dahlia commented Sep 13, 2024

Browser compatibility of the top-level await

It's strange. Does your target environment include any of those unsupported browser versions?

It's unclear to me why fs.js wants to load at all for the browser environment. Could help me to fix the problem?

It does not load fs.js for the browser environment, but just tries to load it, and if it fails it falls back.

@M0ns1gn0r
Copy link
Author

Does your target environment include any of those unsupported browser versions?

The thing is, the target environments from that error message are not defined in our code at all. Looks like they're part of the standard configuration passed to vite by Angular CLI. And according to this issue it's not possible to customize vite's config.

@handlebauer
Copy link

also using vite, also experiencing the same issue

dahlia added a commit that referenced this issue Sep 21, 2024
@dahlia
Copy link
Owner

dahlia commented Sep 21, 2024

Could you try v0.5.2-dev.79+a6c56f26? I addressed the issue and it might be fixed.

dahlia added a commit that referenced this issue Sep 21, 2024
@M0ns1gn0r
Copy link
Author

Unfortunately not, the error is the same, only the line number has changed:

Error: Build failed with 1 error:
node_modules/@logtape/logtape/esm/fs.js:12:9: ERROR: Top-level await is not available in the configured target environment ("chrome121.0", "edge121.0", "firefox115.0", "ios16.0", "safari16.0" + 7 overrides)

dahlia added a commit that referenced this issue Sep 23, 2024
@dahlia
Copy link
Owner

dahlia commented Sep 23, 2024

@M0ns1gn0r Could you try v0.5.2-dev.81+88f228ae? I tested it with Angular CLI, and it apparently works well.

@dahlia dahlia self-assigned this Sep 23, 2024
@dahlia dahlia added the bug Something isn't working label Sep 23, 2024
@M0ns1gn0r
Copy link
Author

Yes, that has fixed it, thank you!

@dahlia
Copy link
Owner

dahlia commented Sep 23, 2024

Shipped with 0.5.2 (JSR & npm).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants