next.js: Cant handle static assets with serverless framework
Bug report
Describe the bug
I cannot load the assets with a lambda with serverless framework.
To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
- Go to https://github.com/romainquellec/boilerplate, clone
- yarn
- yarn (global) add serverless
- yarn build
- yarn lambda
- See error on console or chrome console (assets don’t load)
System information
- OS: Windows
- Version of Next.js: 8.0.1
Additional context
In lambda function, i’m doing :
app.use("/_next/static", express.static("../static"));
app.use("/static", express.static("../static"));
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 15 (12 by maintainers)
Static assets should not be part of the lambdas basically. So indeed use s3 or another static file host.
Changing
app.use("/_next/static", express.static(path.join(__dirname, "/static")));toapp.use("/_next", express.static(path.join(__dirname, ".next")));fixed it.in next.config.js, add:
then in you next app’s root html:
src="/_next/…
will become to :
src="./_next/…
then in your nginx conf:
I’m closing this. Will try to make an example out of it later.