[Feature] Implement a local mode
Allow to run OpenNext (not Next) locally for testing/debugging purposes with a simple command like @opennextjs/aws local or @opennextjs/aws dev
It should be relatively easy, as everything is already in the doc
Are you talking about running the Next.js server locally and also deploying? That should be possible with SST v3. Alternatively, there are instructions for running OpenNext locally in the README. To set up an existing Next.js project with SST, deploy, and run locally:
- From inside your Next.js project directory, run
npx sst@latest init. This will set up the basic SST config files. - Run
npm install(oryarn installdepending on which package manager you're using) to install the new dependencies. - Add the following AWS profile to your
~/.aws/configfile. Make sure to enter the correct value for your AWS SSO login url and AWS account ID.[profile YOUR_AWS_PROFILE_NAME] region=us-east-1 output=json sso_start_url=https://X-XXXXXXXXXX.awsapps.com/start sso_region=us-east-1 sso_role_name=AdministratorAccess sso_account_id=XXXXXXXXXXXX - Modify your package.json file with the following scripts. Replace
YOUR_AWS_PROFILE_NAMEwith the AWS profile... "scripts": { "start": "AWS_PROFILE=YOUR_AWS_PROFILE_NAME sst dev --stage local", "dev": "next dev --experimental-https", "build": "next build", "deploy": "AWS_PROFILE=YOUR_AWS_PROFILE_NAME sst deploy --stage dev", "destroy": "AWS_PROFILE=YOUR_AWS_PROFILE_NAME sst remove --stage dev", "lint": "next lint" }, ... - Prior to running any SST commands, make sure you are logged into your AWS SSO with the command:
aws sso login --profile=YOUR_AWS_PROFILE_NAME - Make any appropriate modifications to your sst.config.ts file. In my case, I added a Custom Domain
- For local development work, run
npm run start. This will initiate the SST tooling and then start the Next.js server in dev mode. - For deployment, run
npm run deploy. This uses a different SST stage than the local to avoid creating/destroying the CloudFront CDN each time you run the project locally.
Does that fit your needs? If you give it a try and run into any issues, feel free to reach out, I'm not 100% sure I got the instructions right from memory and I'm willing to tweak them as needed for clarity or to fix mistakes.
Thanks, but this issue is more a reminder of what i need to do as a PR.
Right now it's a hassle to run OpenNext (not Next) locally, you have to manually create a bunch of wrapper converter and other stuff.
Implementing a @opennextjs/aws local or @opennextjs/aws dev command would be great and helpful for people contributing
@conico974 how exactly would @opennextjs/aws local / dev work?
Basically it would do this https://opennext.js.org/aws/contribute/local_run, but in one command