You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fixes#14338 and
vercel/next.js#85110 (comment).
This PR should fix support for using turbopack to build your Next.js
project (which is now the default in Next.js 16, unless you pass `next
build --webpack`).
Previously, we were directly externalizing dependencies like `libsql` as
they cause an error when being bundled. However, as those dependencies
were not installed at the top-level by the user, the resulting
`require('libsql')` calls could fail in production.
Turbopack threw the following warning:
```bash
Packages that should be external need to be installed in the project directory, so they can be resolved from the output files.\nTry to install it into the project directory by running
````
However, we ignored this warning, as we cannot force users to manually
install dependencies of our dependencies.
In Next.js 16, when using Turbopack build, this is no longer a warning
but an error, which is why attempting to use turbopack build right now
will not work.
This PR properly fixes this externalization issue, by externalizing the
`entry points` of those problematic packages (our db adapters). This
means we no longer need to hide the warning.
'Packages that should be external need to be installed in the project directory, so they can be resolved from the output files.\nTry to install it into the project directory by running'
21
-
22
-
constconsoleWarn=console.warn
23
-
console.warn=(...args)=>{
24
-
// Force to disable serverExternalPackages warnings: https://github.com/vercel/next.js/issues/68805
// Do not bundle server-only packages during dev to improve compile speed
73
+
// These packages always need to be external, both during dev and production. This is because they install dependencies
74
+
// that will error when trying to bundle them (e.g. drizzle-kit, libsql, esbuild etc.).
75
+
// We cannot externalize those problem-packages directly. We can only externalize packages that are manually installed
76
+
// by the end user. Otherwise, the require('externalPackage') calls generated by the bundler would fail during runtime,
77
+
// as you cannot import dependencies of dependencies in a lot of package managers like pnpm. We'd have to force users
78
+
// to install the dependencies directly.
79
+
// Thus, we externalize the "entry-point" = the package that is installed by the end user, which would be our db adapters.
80
+
//
81
+
//
82
+
// External because it installs mongoose (part of default serverExternalPackages: https://github.com/vercel/next.js/blob/canary/packages/next/src/lib/server-external-packages.json => would throw warning if we don't exclude the entry-point package):
83
+
'@payloadcms/db-mongodb',
84
+
// External because they install dependencies like drizzle, libsql, esbuild etc.:
85
+
'@payloadcms/db-postgres',
86
+
'@payloadcms/db-sqlite',
87
+
'@payloadcms/db-vercel-postgres',
88
+
'@payloadcms/drizzle',
89
+
// External because they install @aws-sdk/client-s3:
90
+
'@payloadcms/payload-cloud',
91
+
// TODO: We need to externalize @payloadcms/storage-s3 as well, once Next.js has the ability to exclude @payloadcms/storage-s3/client from being externalized.
92
+
// Do not bundle additional server-only packages during dev to improve compilation speed
0 commit comments