Package Exports
- @netlify/plugin-nextjs
- @netlify/plugin-nextjs/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@netlify/plugin-nextjs) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Next.js Runtime
Next.js is supported natively on Netlify, and in most cases you will not need to install or configure anything. This repo includes the packages used to support Next.js on Netlify.
Lambda Folder structure:
For a simple next.js app
/___netlify-server-handler
├── .netlify
│ ├── tags-manifest.json
│ └── dist // the compiled runtime code
│ └── run
│ ├── handlers
│ │ ├── server.js
│ │ └── cache.cjs
│ └── next.cjs
├── .next // or distDir name from the next.config.js
│ └── // content from standalone
├── run-config.json // the config object from the required-server-files.json
├── node_modules
├── ___netlify-server-handler.json
├── ___netlify-server-handler.mjs
└── package.jsonTesting
Integration testing
How to add new integration test scenarios to the application:
- Create a new folder under
tests/fixtures/<your-name> - Adapt the
next.config.jsto be a standalone application - Create a
postinstallscript that runs thenext build. It's important to notice that the integration tests rely on a already built next.js application in this folder. They rely on the.nextfolder. - Add your test
Currently the tests require a built version of the
dist/run/handlers/cache.cjsso you need to runnpm run buildbefore executing the integration tests.
In addition, the integration tests need to be prepared before first use. You can do this by running
npm run pretest. To speed up this process and build only the fixtures whose name starts with a
given prefix, run npm run pretest -- <prefix>.
E2E testing
Prerequisite
Needs the
netlify-cliinstalled and being logged in having access to Netlify Testing Organization
The e2e tests can be invoked with npm run e2e and perform a full e2e test. This means they do the
following:
- Building the next-runtime (just running
npm run buildin the repository) - Creating a temp directory and copying the provided fixture over to the directory.
- Packing the runtime with
npm packto the temp directory. - Installing the runtime from the created zip artifact of
npm pack(this is like installing a node_module from the registry) - Creating a
netlify.tomlinside the temp directory of the fixture and adding the runtime as a plugin. - Running
netlify deploy --buildinvoking the runtime. This will use the next-runtime-testing as site to deploy to. - Using the
deployIdandurlof the deployed site to run some playwright tests against, asserting the correctness of the runtime. - After the tests where run successfully, it will delete the deployment again and clean everything up. In case of a failure, the deploy won't be cleaned up to leave it for troubleshooting purposes.
[!TIP] If you'd like to always keep the deployment and the local fixture around for troubleshooting, run
E2E_PERSIST=1 npm run e2e.
cleanup old deploys
To cleanup old and dangling deploys from failed builds you can run the following script:
npx tsx ./tools/e2e/cleanup-deploys.tsThis will cleanup all created deploys on the next-runtime-testing site.