[ERROR] Top-level await is currently not supported with the "cjs" output format

in getRas.ts file i import like thisimport { decrypt_rsa, greet } from "./wasm-rsa-server-decrypt/pkg/wasm_rsa_server_decrypt.js";,it’ok in my local

11:04:15 AM: Netlify Build
11:04:15 AM: ────────────────────────────────────────────────────────────────
11:04:15 AM: ​
11:04:15 AM: ❯ Version
11:04:15 AM: @netlify/build 29.23.4
11:04:15 AM: ​
11:04:15 AM: ❯ Flags
11:04:15 AM: baseRelDir: true
11:04:15 AM: buildId: 65349118ffd20e6b0aea29dd
11:04:15 AM: deployId: 65349118ffd20e6b0aea29df
11:04:15 AM: ​
11:04:15 AM: ❯ Current directory
11:04:15 AM: /opt/build/repo
11:04:15 AM: ​
11:04:15 AM: ❯ Config file
11:04:15 AM: /opt/build/repo/netlify.toml
11:04:15 AM: ​
11:04:15 AM: ❯ Context
11:04:15 AM: production
11:04:15 AM: ​
11:04:15 AM: Build command from Netlify app
11:04:15 AM: ────────────────────────────────────────────────────────────────
11:04:15 AM: ​
11:04:15 AM: $ yarn build
11:04:15 AM: yarn run v1.22.19
11:04:15 AM: $ docusaurus build
11:04:16 AM: [INFO] [zh-Hans] Creating an optimized production build…
11:04:17 AM: [info] [webpackbar] Compiling Client
11:04:17 AM: [info] [webpackbar] Compiling Server
11:04:23 AM: [success] [webpackbar] Client: Compiled successfully in 6.30s
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》litttley (rgwu) · GitHub
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》litttley (rgwu) · GitHub
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》litttley (rgwu) · GitHub
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》litttley (rgwu) · GitHub
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》litttley (rgwu) · GitHub
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》litttley (rgwu) · GitHub
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》litttley (rgwu) · GitHub
11:04:26 AM: {
11:04:26 AM: title: “指极轩”,
11:04:26 AM: tagline: “命道医三元归一”,
11:04:26 AM: favicon: “img/favicon.ico”,
11:04:26 AM: url: “https://zhijixuan.netlify.app”,
11:04:26 AM: baseUrl: “/”,
11:04:26 AM: organizationName: “facebook”,
11:04:26 AM: projectName: “docusaurus”,
11:04:26 AM: onBrokenLinks: “throw”,
11:04:26 AM: onBrokenMarkdownLinks: “warn”,
11:04:26 AM: i18n: {
11:04:26 AM: defaultLocale: “zh-Hans”,
11:04:26 AM: locales: [ “zh-Hans” ],
11:04:26 AM: path: “i18n”,
11:04:26 AM: localeConfigs: {}
11:04:26 AM: },
11:04:26 AM: plugins: [
11:04:26 AM: [ “@docusaurus/plugin-content-docs”, [Object] ],
11:04:26 AM: [ “@docusaurus/plugin-content-docs”, [Object] ],
11:04:26 AM: [ “@docusaurus/plugin-content-docs”, [Object] ],
11:04:26 AM: [ “@docusaurus/plugin-content-docs”, [Object] ],
11:04:26 AM: null
11:04:26 AM: ],
11:04:26 AM: presets: [ [ “classic”, [Object] ] ],
11:04:26 AM: themeConfig: {
11:04:26 AM: image: “img/docusaurus-social-card.jpg”,
11:04:26 AM: navbar: {
11:04:26 AM: title: “指极轩”,
11:04:26 AM: logo: [Object],
11:04:26 AM: items: [Array],
11:04:26 AM: hideOnScroll: false
11:04:26 AM: },
11:04:26 AM: footer: {
11:04:26 AM: style: “dark”,
11:04:26 AM: links: [Array],
11:04:26 AM: copyright: “Copyright © 2019-2023 指极轩.”
11:04:26 AM: },
11:04:26 AM: prism: {
11:04:26 AM: theme: [Object],
11:04:26 AM: darkTheme: [Object],
11:04:26 AM: additionalLanguages: ,
11:04:26 AM: magicComments: [Array]
11:04:26 AM: },
11:04:26 AM: colorMode: {
11:04:26 AM: defaultMode: “light”,
11:04:26 AM: disableSwitch: false,
11:04:26 AM: respectPrefersColorScheme: false
11:04:26 AM: },
11:04:26 AM: docs: { versionPersistence: “localStorage”, sidebar: [Object] },
11:04:26 AM: metadata: ,
11:04:26 AM: tableOfContents: { minHeadingLevel: 2, maxHeadingLevel: 3 }
11:04:26 AM: },
11:04:26 AM: baseUrlIssueBanner: true,
11:04:26 AM: onDuplicateRoutes: “warn”,
11:04:26 AM: staticDirectories: [ “static” ],
11:04:26 AM: customFields: {},
11:04:26 AM: themes: ,
11:04:26 AM: scripts: ,
11:04:26 AM: headTags: ,
11:04:26 AM: stylesheets: ,
11:04:26 AM: clientModules: ,
11:04:26 AM: titleDelimiter: “|”,
11:04:26 AM: noIndex: false,
11:04:26 AM: markdown: {
11:04:26 AM: format: “mdx”,
11:04:26 AM: mermaid: false,
11:04:26 AM: mdx1Compat: { comments: true, admonitions: true, headingIds: true }
11:04:26 AM: }
11:04:26 AM: }
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》litttley (rgwu) · GitHub
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》litttley (rgwu) · GitHub
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》litttley (rgwu) · GitHub
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》litttley (rgwu) · GitHub
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》litttley (rgwu) · GitHub
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》litttley (rgwu) · GitHub
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》litttley (rgwu) · GitHub
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》litttley (rgwu) · GitHub
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》litttley (rgwu) · GitHub
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》litttley (rgwu) · GitHub
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》litttley (rgwu) · GitHub
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》litttley (rgwu) · GitHub
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》litttley (rgwu) · GitHub
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》litttley (rgwu) · GitHub
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》litttley (rgwu) · GitHub
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》litttley (rgwu) · GitHub
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》litttley (rgwu) · GitHub
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》litttley (rgwu) · GitHub
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》litttley (rgwu) · GitHub
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》litttley (rgwu) · GitHub
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》litttley (rgwu) · GitHub
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》litttley (rgwu) · GitHub
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》litttley (rgwu) · GitHub
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》litttley (rgwu) · GitHub
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》litttley (rgwu) · GitHub
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》litttley (rgwu) · GitHub
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》litttley (rgwu) · GitHub
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》litttley (rgwu) · GitHub
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》litttley (rgwu) · GitHub
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》litttley (rgwu) · GitHub
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》litttley (rgwu) · GitHub
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》litttley (rgwu) · GitHub
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》litttley (rgwu) · GitHub
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》litttley (rgwu) · GitHub
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》litttley (rgwu) · GitHub
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》litttley (rgwu) · GitHub
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》#
11:04:26 AM: href===》litttley (rgwu) · GitHub
11:04:27 AM: [success] [webpackbar] Server: Compiled successfully in 9.56s
11:04:28 AM: Failed during stage “building site”: Build script returned non-zero exit code: 2
11:04:28 AM: [SUCCESS] Generated static files in “build”.
11:04:28 AM: [INFO] Use npm run serve command to test your build locally.
11:04:28 AM: Done in 12.37s.
11:04:28 AM: ​
11:04:28 AM: (build.command completed in 12.5s)
11:04:28 AM: ​
11:04:28 AM: Functions bundling
11:04:28 AM: ────────────────────────────────────────────────────────────────
11:04:28 AM: ​
11:04:28 AM: Packaging Functions from netlify/edge-functions directory:
11:04:28 AM: - getProducts.ts
11:04:28 AM: - getRas.ts
11:04:28 AM: - loginUser.ts
11:04:28 AM: ​
11:04:28 AM: ✘ [ERROR] Top-level await is currently not supported with the “cjs” output format
11:04:28 AM: netlify/edge-functions/wasm-rsa-server-decrypt/pkg/wasm_rsa_server_decrypt.js:162:15:
11:04:28 AM: 162 │ wasmCode = await Deno.readFile(wasm_url);
11:04:28 AM: ╵ ~~~~~
11:04:28 AM: ✘ [ERROR] Top-level await is currently not supported with the “cjs” output format
11:04:28 AM: netlify/edge-functions/wasm-rsa-server-decrypt/pkg/wasm_rsa_server_decrypt.js:166:15:
11:04:28 AM: 166 │ wasmCode = await (await fetch(wasm_url)).arrayBuffer();
11:04:28 AM: ╵ ~~~~~
11:04:28 AM: ✘ [ERROR] Top-level await is currently not supported with the “cjs” output format
11:04:28 AM: netlify/edge-functions/wasm-rsa-server-decrypt/pkg/wasm_rsa_server_decrypt.js:166:22:
11:04:28 AM: 166 │ wasmCode = await (await fetch(wasm_url)).arrayBuffer();
11:04:28 AM: ╵ ~~~~~
11:04:28 AM: ✘ [ERROR] Top-level await is currently not supported with the “cjs” output format
11:04:28 AM: netlify/edge-functions/wasm-rsa-server-decrypt/pkg/wasm_rsa_server_decrypt.js:172:22:
11:04:28 AM: 172 │ const wasmInstance = (await WebAssembly.instantiate(wasmCode, imp…
11:04:28 AM: ╵ ~~~~~
11:04:28 AM: ✘ [ERROR] Top-level await is currently not supported with the “cjs” output format
11:04:28 AM: netlify/edge-functions/wasm-rsa-server-decrypt/pkg/wasm_rsa_server_decrypt.js:162:15:
11:04:28 AM: 162 │ wasmCode = await Deno.readFile(wasm_url);
11:04:28 AM: ╵ ~~~~~
11:04:28 AM: ✘ [ERROR] Top-level await is currently not supported with the “cjs” output format
11:04:28 AM: netlify/edge-functions/wasm-rsa-server-decrypt/pkg/wasm_rsa_server_decrypt.js:166:15:
11:04:28 AM: 166 │ wasmCode = await (await fetch(wasm_url)).arrayBuffer();
11:04:28 AM: ╵ ~~~~~
11:04:28 AM: ✘ [ERROR] Top-level await is currently not supported with the “cjs” output format
11:04:28 AM: netlify/edge-functions/wasm-rsa-server-decrypt/pkg/wasm_rsa_server_decrypt.js:166:22:
11:04:28 AM: 166 │ wasmCode = await (await fetch(wasm_url)).arrayBuffer();
11:04:28 AM: ╵ ~~~~~
11:04:28 AM: ✘ [ERROR] Top-level await is currently not supported with the “cjs” output format
11:04:28 AM: netlify/edge-functions/wasm-rsa-server-decrypt/pkg/wasm_rsa_server_decrypt.js:172:22:
11:04:28 AM: 172 │ const wasmInstance = (await WebAssembly.instantiate(wasmCode, imp…
11:04:28 AM: ╵ ~~~~~
11:04:28 AM: ​
11:04:28 AM: Bundling of function “getRas” failed
11:04:28 AM: ────────────────────────────────────────────────────────────────
11:04:28 AM: ​
11:04:28 AM: Error message
11:04:28 AM: Build failed with 4 errors:
11:04:28 AM: netlify/edge-functions/wasm-rsa-server-decrypt/pkg/wasm_rsa_server_decrypt.js:162:15: ERROR: Top-level await is currently not supported with the “cjs” output format
11:04:28 AM: netlify/edge-functions/wasm-rsa-server-decrypt/pkg/wasm_rsa_server_decrypt.js:166:15: ERROR: Top-level await is currently not supported with the “cjs” output format
11:04:28 AM: netlify/edge-functions/wasm-rsa-server-decrypt/pkg/wasm_rsa_server_decrypt.js:166:22: ERROR: Top-level await is currently not supported with the “cjs” output format
11:04:28 AM: netlify/edge-functions/wasm-rsa-server-decrypt/pkg/wasm_rsa_server_decrypt.js:172:22: ERROR: Top-level await is currently not supported with the “cjs” output format
11:04:28 AM: ​
11:04:28 AM: Error location
11:04:28 AM: While bundling function “getRas”
11:04:28 AM: ​
11:04:28 AM: Resolved config
11:04:28 AM: build:
11:04:28 AM: command: yarn build
11:04:28 AM: commandOrigin: ui
11:04:28 AM: edge_functions: /opt/build/repo/netlify/edge-functions
11:04:28 AM: environment:
11:04:28 AM: - POLYSCALE_SUPABASE_URL
11:04:28 AM: publish: /opt/build/repo/build
11:04:28 AM: publishOrigin: ui
11:04:28 AM: functionsDirectory: /opt/build/repo/netlify/edge-functions
11:04:28 AM: Build failed due to a user error: Build script returned non-zero exit code: 2
11:04:28 AM: Failing build: Failed to build site
11:04:29 AM: Finished processing build request in 34.983s

Have you added type: module to your package.json?

i’am use the wasm-pack build https://rustwasm.github.io/docs/wasm-bindgen/reference/deployment.html with --target deno ,it’s have no package.json only function ,and my local is work well.

i’am use the wasm-pack build https://rustwasm.github.io/docs/wasm-bindgen/reference/deployment.html with --target deno ,it’s have no package.json only function ,and my local is work well.

If you’re using target deno, are you using it in Edge Functions or the Lambda Functions? From the error it appears to be in the Lambda Functions. Not sure if that’s supposed to work.

wasm_rsa_server_decrypt.js

const wasm_url = new URL('wasm_rsa_server_decrypt_bg.wasm', import.meta.url);
let wasmCode = '';
switch (wasm_url.protocol) {
    case 'file:':
    wasmCode = await Deno.readFile(wasm_url);
    break
    case 'https:':
    case 'http:':
    wasmCode = await (await fetch(wasm_url)).arrayBuffer();
    break
    default:
    throw new Error(`Unsupported protocol: ${wasm_url.protocol}`);
}

does netlify support Deno.readFile?

File system is not supported as far as I’m aware.

yes,i have solve this throw https like this

import { decrypt_rsa, greet } from "https://xxx.com/wasm-rsa-server-decrypt/pkg/wasm_rsa_server_decrypt.js";

sorry please rephrase what you are asking? I’m unclear on your request.

this issue has been solved

thanks for confirming!