Closed samtgarson closed 4 months ago
Experiencing the same issue with 2 packages, pdfjs and tiktoken.
Updating 14.1.4 -> 14.2.2 produces these warnings on an otherwise clean npm run build
:
> next build
▲ Next.js 14.2.2
Creating an optimized production build ...
⚠ Compiled with warnings
./node_modules/pdfjs-dist/build/pdf.mjs
The generated code contains 'async/await' because this module is using "topLevelAwait".
However, your target environment does not appear to support 'async/await'.
As a result, the code may not run as expected or may cause runtime errors.
Import trace for requested module:
./node_modules/pdfjs-dist/build/pdf.mjs
./src/common/util/pdfUtils.ts
./src/apps/chat/components/composer/attachments/pipeline.tsx
./src/apps/chat/components/composer/attachments/store-attachments.tsx
./src/apps/chat/components/composer/attachments/useAttachments.tsx
./src/apps/chat/components/composer/Composer.tsx
./src/apps/chat/AppChat.tsx
./node_modules/tiktoken/tiktoken_bg.wasm
The generated code contains 'async/await' because this module is using "asyncWebAssembly".
However, your target environment does not appear to support 'async/await'.
As a result, the code may not run as expected or may cause runtime errors.
Import trace for requested module:
./node_modules/tiktoken/tiktoken_bg.wasm
./node_modules/tiktoken/tiktoken.js
./src/common/util/token-counter.ts
./src/common/providers/ProviderBackendCapabilities.tsx
✓ Linting and checking validity of types
...
I'm experiencing the same issue since I migrated from Next v14.1.4 to v14.2.1, using @prisma/client v5.12.1. My prisma setup:
generator client {
provider = "prisma-client-js"
previewFeatures = ["driverAdapters"]
}
const neon = new Pool({ connectionString: process.env["DATABASE_URL"] });
const adapter = new PrismaNeon(neon);
const prisma = new PrismaClient({ adapter });
When attempting to access the DB from middleware.ts:
⚠ ../../node_modules/.pnpm/@prisma+client@5.12.1_prisma@5.12.1/node_modules/.prisma/client/wasm-edge-light-loader.js
The generated code contains 'async/await' because this module is using "topLevelAwait".
However, your target environment does not appear to support 'async/await'.
As a result, the code may not run as expected or may cause runtime errors.
Import trace for requested module:
../../node_modules/.pnpm/@prisma+client@5.12.1_prisma@5.12.1/node_modules/.prisma/client/wasm-edge-light-loader.js
../../node_modules/.pnpm/@prisma+client@5.12.1_prisma@5.12.1/node_modules/.prisma/client/wasm.js
../../node_modules/.pnpm/@prisma+client@5.12.1_prisma@5.12.1/node_modules/.prisma/client/default.js
../../node_modules/.pnpm/@prisma+client@5.12.1_prisma@5.12.1/node_modules/@prisma/client/default.js
./src/lib/prisma.ts
facing the same issue when import vtracer-webapp:
The generated code contains 'async/await' because this module is using "asyncWebAssembly".
However, your target environment does not appear to support 'async/await'.
As a result, the code may not run as expected or may cause runtime errors.
I find it is related with webpack experiment feeature:
// next.config.js
{
webpack: (config) => {
config.experiments = {
asyncWebAssembly: true,
syncWebAssembly: true,
layers: true,
};
return config;
},
}
This is not a bug of swc minifier / terser, and the error message is correct. edge runtime does not support top-level awaits.
See https://www.prisma.io/docs/orm/prisma-client/deployment/edge/overview
@kdy1 Please check whether the reference URL you provided is accurate. The URL indicates that Prisma can operate on NextJS middleware.
I confirmed that edge runtime does not support top-level awaits. Therefore, it seems like this issue should be created in Prisma rather than NextJS.
As edge runtime stops supporting await It has been confirmed that several libraries and services are experiencing failures.
We couldn't find any other tickets similar to this issue I'd love to hear about future patch plans or reasons for patching in this issue.
@kdy1 things seem to work with both asyncWebAssembly and topLevelAwait, because the environment is the browser.
Somehow the warnings are emitted verbosely when compiling various routes, despite the target being the browser and not the edge runtime.
Is there a way to suppress this warning? Is the warning incorrect?
Updating pdfjs-dist
to 4.36.136 removes the warning (topLevelAwait
).
Warning still present for asyncWebAssembly
on tiktoken. (note it's not used by the edge function, it's only used in the browser)
To silence the warning, I used the following:
...
webpack: (config, { isServer }) => {
...
// @dqbd/tiktoken: enable asynchronous WebAssembly
config.experiments = {
asyncWebAssembly: true,
layers: true,
};
// fix warnings for async functions in the browser (https://github.com/vercel/next.js/issues/64792)
if (!isServer) {
config.output.environment = { ...config.output.environment, asyncFunction: true };
}
...
return config;
},
...
Came here for TikToken problems in browser lol thanks!
This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.
Link to the code that reproduces this issue
https://github.com/samtgarson/next-edge-prisma-reproduction
To Reproduce
npm run build
Current vs. Expected behavior
I expect no error to be thrown
Provide environment information
Which area(s) are affected? (Select all that apply)
Runtime, Turbopack, SWC
Which stage(s) are affected? (Select all that apply)
next dev (local), next build (local)
Additional context
The reproduction provided demonstrates the error, but does not demonstrate the panic I receive on the production repo (https://github.com/samtgarson/books-about-food/tree/cloudflare)
In this repo, the build fails completely with the following error:
This only occurs when runtime is set to
edge
(even in a single page) and completely explodes the build.(side note: I'm not sure why this larger repo seems to be using Terser when I've not disabled
swcMinify
)This has been occurring for at least a couple of minor versions.
Related: https://github.com/vercel/next.js/issues/63283 https://github.com/vercel/next.js/issues/51077 https://github.com/prisma/prisma/issues/21780#issuecomment-2061783971 https://github.com/prisma/prisma/issues/23600 https://github.com/vercel/next.js/issues/31054