Replies: 4 comments
-
For those curious about a workaround, in our production containers without optional dependencies we need to selectively pick from a platform specific module, and install it like |
Beta Was this translation helpful? Give feedback.
-
Looks like a minor has adopted a new way to resolve swc binaries ( changed radically between 15.3.2 and 15.3.4 ). Nevertheless, the fact that next installs playwright by default when you run |
Beta Was this translation helpful? Give feedback.
-
Closing in favour of a new ticket since SWC downloader has changed in last minor version. |
Beta Was this translation helpful? Give feedback.
-
Why would you have Playwright dependency in fresh Nextjs project to begin with? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Update: Between 15.3.2 and 15.3.4 the swc binary download hack was substantially changed making some of the commentary below incorrect now. I am closing in favour of a new ticket.
Goals
next start
without including unnecessary dependencies especially test-only modules like playwright (and probably without build-time modules like swc)Non-Goals
There is nothing wrong with playwright or swc as dev deps, but these need to be separable for production containers!
Background
Currently if you install a project like...
pnpm install --prod
It brings with it a whole host of dependencies which are incorrect for production deployment. An example is the babel react compiler and the playwright test framework, as you can see here...
next.js/packages/next/package.json
Lines 118 to 129 in 09a2167
Although this already seems like a misuse of
optional
to be stricter with the install you can run...pnpm install --prod --no-optional
However, if you pursue this line (e.g. trying to build a docker environment with only non-optional prod dependencies, plus a built
.next
folder) you will find thatnpm exec next start
fails given its resolution of swc depends on optional dependencies being installed, meaning it's not possible to separate these non-production dependencies at all...That's because SWC is resolved as an optional dependency (presumably because it's multi-platform Rust). So therefore if you try to install and run next without optional dependencies next can't run at all. It attempts to patch itself dynamically, which is a bad idea in a server infrastructure, and also fails at that.
I spent an age trying to work out what was wrong with our build pipelines that was bringing in the whole of Playwright, and then I found astonishingly it was deliberate and part of NextJS. However, trying to REMOVE playwright proves to be impossible thanks to the uncleanliness of optional dependencies in Next.
Proposal
Beta Was this translation helpful? Give feedback.
All reactions