Giter Site home page Giter Site logo

netlify / next-on-netlify Goto Github PK

View Code? Open in Web Editor NEW
718.0 21.0 65.0 2.41 MB

Build and deploy Next.js applications with Server-Side Rendering on Netlify!

License: MIT License

JavaScript 100.00%
netlify-functions nextjs next-on-netlify netlify netlify-deployment serverless server-side-rendering lambda-functions

next-on-netlify's Introduction

Deprecating next-on-netlify

We are deprecating next-on-netlify in favor of Netlify's Essential Next.js Build Plugin. Please visit this issue to learn more about the deprecation of next-on-netlify and ask any questions. You can also visit our simple Migration doc for assistance migrating to the plugin.

Next.js on Netlify

next-on-netlify is a utility for enabling server-side rendering in Next.js on Netlify. It wraps your application in a tiny compatibility layer, so that pages can use Netlify Functions to be server-side rendered.

Table of Contents

Installation

npm install --save next-on-netlify

Setup

1. Set Next.js target to serverless

We must build our Next.js app as a serverless app. You can read more about serverless Next.js here.

It's super simple. Just create a next.config.js file in the root of your project and write the following:

// next.config.js

module.exports = {
  // Target must be serverless
  target: "serverless",
};

If binaries are needed in the deployment the following configuration is needed (Prisma is an example):

// next.config.js

module.exports = {
  // Target must be experimental-serverless-trace
  // Your build time will be longer with this option
  target: "experimental-serverless-trace",
};

2. Add postbuild hook

The next-on-netlify package adds the next-on-netlify command. When we run this command, some magic happens to prepare our Next.js app for hosting on Netlify*.

We want the next-on-netlify command to run after we build our Next.js application. So let's add a postbuild hook to our package.json file. You should add "postbuild": "next-on-netlify" to the existing scripts, like so:

{
  "name": "my-nextjs-app",
  "scripts": {
    "dev": "next",
    "build": "next build",
    "postbuild": "next-on-netlify"
  },
  ...
}

*If you're curious about the "magic", check out the well-documented next-on-netlify.js file.

3. Configure for Netlify

We're almost done! We just have to tell Netlify how to build our Next.js app, where the functions folder is located, and which folder to upload to its CDN. We do that with a netlify.toml file in the root of your project and the following instructions:

[build]
  command   = "npm run build"
  functions = "out_functions"
  publish   = "out_publish"

Note: out_functions and out_publish are hard-coded into next-on-netlify. These are not configurable at the moment.

(Optional) Configure private git submodules

If your project contains private submodules, in order to deploy it, you will need to:

  1. Generate a Deploy Key in Netlify and add it to the relevant submodules so that they can be cloned during the deploy process.

  2. Ensure the submodule remotes are set to SSH format (i.e. [email protected]:owner/project.git, not https://...). Inside the submodule directory, the git remote can be updated with:

    # git remote set-url [remote] [url]
    git remote set-url origin [email protected]:owner/project.git

We're done. Let's deploy πŸš€πŸš€πŸš€

If you're not familiar with Netlify, follow the deployment instructions here: https://www.netlify.com/blog/2020/11/30/how-to-deploy-next.js-sites-to-netlify/

Demo

Optional Extras

Preview Locally

I recommend you still use next dev to build and preview your application locally.

But if you want to emulate the Netlify deployment on your computer, you can also run next-on-netlify locally and then use netlify-cli to preview the result.

First, install the latest version of netlify-cli (you can also look at package.json to see the version that next-on-netlify has been tested against):

npm install -g netlify-cli

Then, add the following [dev] block to your netlify.toml:

# netlify.toml

# [build]
#   ...

[dev]
  functions = "out_functions"
  publish   = "out_publish"
  # We manually set the framework to static, otherwise Netlify automatically
  # detects Next.js and redirects do not work.
  # Read more: https://github.com/netlify/cli/blob/master/docs/netlify-dev.md#project-detection
  framework = "#static"

Lastly, add the following lines to your .gitignore:

# .gitignore

# Files generated by next-on-netlify command
/out_publish/
/out_functions/

Now you're all set.

From now on, whenever you want to preview your application locally, just run:

  1. npx next-on-netlify watch: This will run next build to build your Next.js app and next-on-netlify to prepare your Next.js app for compatibility with Netlify. Any source code changes will trigger another build.
  2. netlify dev: This will emulate Netlify on your computer and let you preview your app on http://localhost:8888.

Note:

Preview Mode is not yet available locally, running netlify dev, for static pages without revalidate or fallback. This will be supported soon.

For now, Preview Mode is supported in production for all Next.js page types.

Custom Netlify Redirects

You can define custom redirects in a _redirects and/or in your netlify.toml file. The precedence of these rules are:

  • _redirects
  • next-on-netlify redirects

Currently, there is no support for redirects set in your netlify.toml file.

Read more about Netlify redirects here.

Custom Netlify Functions

next-on-netlify creates one Netlify Function for each of your SSR pages and API endpoints. Currently, you can only create custom Netlify functions using @netlify/plugin-nextjs.

Background Functions

If your Next.js API page/route ends in -background, it will be treated as a Netlify background function. Note: background functions are only available on certain plans.

Using Netlify Identity

You can use Netlify Identity with next-on-netlify. For all pages with server-side rendering (getInitialProps*, getServerSideProps, and API routes), you can access the clientContext object via the req parameter.

For example:

const Page = () => <p>Hello World!</p>;

export const getServerSideProps = async ({ req }) => {
  // Get event and context from Netlify Function
  const {
    netlifyFunctionParams: { event, context },
  } = req;

  // Access Netlify identity
  const { identity, user } = context.clientContext;

  return {
    props: {},
  };
};

export default Page;

To access Netlify Identity from pages without server-side rendering, you can create a Next API route that performs identity-related logic:

export default async function getUser(req, res) {
  // Get event and context from Netlify Function
  const {
    netlifyFunctionParams: { event, context },
  } = req;

  // Access Netlify identity
  const { user } = context.clientContext;

  // Respond with user object
  res.json({ user });
}

* Note that pages using getInitialProps are only server-side rendered on initial page load and not when the user navigates client-side between pages.

Caveats

Fallbacks for Pages with getStaticPaths

Fallback pages behave differently with next-on-netlify than they do with Next.js. On Next.js, when navigating to a path that is not defined in getStaticPaths, it first displays the fallback page. Next.js then generates the HTML in the background and caches it for future requests.

With next-on-netlify, when navigating to a path that is not defined in getStaticPaths, it server-side renders the page and sends it directly to the user. The user never sees the fallback page. The page is not cached for future requests.

For more on this, see: Issue #7

next/image

Our existing solution for next/image is not very performant. We have performance improvements on our roadmap, dependent on internal work.

To get better performance now, we recommend using a cloud provider like Cloudinary (see the Next.js docs).

Credits

This package is maintained by Lindsay Levine, Finn Woelm, and Cassidy Williams.

πŸ“£ Shoutout to @mottox2 (a pioneer of hosting Next.js on Netlify) and @danielcondemarin (author of serverless-next.js for AWS). The two were big inspirations for this package.

πŸ™Œ Big "thank you" to the following people for their contributions, support, and beta testing:

Showcase

The following sites are built with next-on-netlify:

opinionatedreact.com
opinionatedreact.com (via Twitter)

missionbit.org
missionbit.org (#18)

gemini.com

gemini.com

bigbinary.com

bigbinary.com

next-cms-ghost

Create your own blog and deploy to Netlify!

Are you building something awesome with next-on-netlify? πŸ”₯ Let us know and we will feature it here :)

next-on-netlify's People

Contributors

afzalsayed96 avatar brandonklotz avatar cassidoo avatar dependabot[bot] avatar ehmicky avatar erezrokah avatar etrepum avatar finnwoelm avatar garrypolley avatar ikristy avatar jonasbuntinx avatar joostmeijles avatar jovidecroock avatar leomeneguzzi avatar lindsaylevine avatar piyushsi avatar rajington avatar ritaxcorreia avatar sdras avatar spencewood avatar styxlab avatar tlakomy avatar tools-netlify avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

next-on-netlify's Issues

Error: Cannot find module 'next-aws-lambda' when using yarn 2

"Cannot find module 'next-aws-lambda'\n" +
'Require stack:\n' +
'- C:\Users\Riz\Desktop\basey2\out_functions\next_api_hello\next_api_hello.js\n' +
'- C:\Users\Riz\scoop\persist\nvm\nodejs\v14.10.1\node_modules\netlify-cli\node_modules\lambda-local\build\lambdalocal.js\n' +
'- C:\Users\Riz\scoop\persist\nvm\nodejs\v14.10.1\node_modules\netlify-cli\src\utils\serve-functions.js\n' +
'- C:\Users\Riz\scoop\persist\nvm\nodejs\v14.10.1\node_modules\netlify-cli\src\commands\dev\index.js\n' +
'- C:\Users\Riz\scoop\persist\nvm\nodejs\v14.10.1\node_modules\netlify-cli\node_modules\@oclif\config\lib\plugin.js\n' +
'- C:\Users\Riz\scoop\persist\nvm\nodejs\v14.10.1\node_modules\netlify-cli\node_modules\@oclif\config\lib\config.js\n' +
'- C:\Users\Riz\scoop\persist\nvm\nodejs\v14.10.1\node_modules\netlify-cli\node_modules\@oclif\config\lib\index.js\n' +
'- C:\Users\Riz\scoop\persist\nvm\nodejs\v14.10.1\node_modules\netlify-cli\node_modules\@oclif\command\lib\command.js\n' +
'- C:\Users\Riz\scoop\persist\nvm\nodejs\v14.10.1\node_modules\netlify-cli\node_modules\@oclif\command\lib\index.js\n' +
'- C:\Users\Riz\scoop\persist\nvm\nodejs\v14.10.1\node_modules\netlify-cli\src\index.js\n' +
'- C:\Users\Riz\scoop\persist\nvm\nodejs\v14.10.1\node_modules\netlify-cli\bin\run',

Custom Redirects Not Showing Up In Production Build _redirects File

Hi there!

Thank you so much for this awesome utility. We have been loving it so far!

We're running into an issue where our custom redirects are showing up in our local build, but when deploying to Netlify, all we see are the # Next-on-Netlify Redirects.

Here's our netlify.toml file:

[build]
  command   = "npm run build"
  functions = "out_functions"
  publish   = "out_publish"

[dev]
  functions = "functions"
  publish   = "public"
  # We manually set the framework to static, otherwise Netlify automatically
  # detects NextJS and redirects do not work.
  # Read more: https://github.com/netlify/cli/blob/master/docs/netlify-dev.md#project-detection
  framework = "#static"

Here's our _redirect file in the root of our project that should redirect /test to our home page:

/test/ /

Here are our scripts in our package.json:

  "scripts": {
    "dev": "next",
    "build": "next build",
    "start": "next start",
    "postbuild": "next-on-netlify"
  },

The custom redirect does not get added to the out_publish/_redirects file on Netlify, but if we create build locally, it does.

We've even tried re-deploying with cache clear and no luck.
image

Do you have any ideas of what might be happening here? We also tried adding this redirect to our netlify.toml file, and still had no luck.

Thank you!

Monorepo with yarn workspaces.

Hey and thanks very much for this project!!

I have a project structure that follows something like this

  • WebApp1
  • WebApp2
  • Components
  • Library

And i am using the yarn workspaces to make possible using the components in the webapp1, but when i tried to deploy on netlify is says that its requires aws lamba package.

I have tried to put the nohoist option in webapp1 to prevent the child project packages going to the root and tried locally running the netlify but when i deploy its still failling.

Any idea what can be the issue?
My best regards,
Vitor

500 Errors with dynamic routes + getStaticProps

I'm so excited about v2 of this library! Unfortunately I ran into a couple issues with it when trying to query an API based on a dynamic route.

Here's what my code looked like before with getStaticProps and using the new incremental stuff:
https://github.com/cassidoo/sonnet-18/blob/c91e5468e5524b773537a89b73fbd7632ea735e4/pages/compare/%5B...slug%5D.js

And it works great when I change it to use getInitialProps:
https://github.com/cassidoo/sonnet-18/blob/master/pages/compare.js

The code is doing pretty much the exact same thing, except I pull it from a query string in the latter, and from the dynamic path in the first one. It worked fine locally on my machine, but on Netlify itself when I tried to navigate to the paths, it gave a 500 error.
I do prefer the query string way, but when talking with the Next.js team themselves, they recommended the other way with the paths, and I'd like to stick with the recommended way if I can.

I tried debugging a few times but this seems to the the only working solution for now. Happy to give more info if needed!

Error enabling offline persistence with Firebase Web SDK and SSR

I am trying to use the Google Firebase Web SDK (Firestore, Storage and Analytics) on a Next.js project hosted on Netlify with next-on-netlify.

I have some pages strictly using Firebase Firestore APIs once the page has loaded, and other pages are using Firestore APIs within the getServerSideProps() function. Still inconclusive, but it appears that the pages using Firestore within getServerSideProps are not working. There are two symptoms:

  1. Pages timeout when trying to visit them through a browser, with the following returned:
{"errorMessage":"2020-10-28T23:52:17.325Z 4833e28b-d8c9-47bb-ad04-39d813a0b378 Task timed out after 10.01 seconds"}
  1. If I navigate to the function logs in Netlify, where it appears to have generated a function for the SSR page, the logs are going crazy with the following line printed hundreds of times every minute:
11:51:22 PM: 2020-10-28T23:51:22.407Z	516720dc-661b-4f02-928d-6ca151031376	WARN	Error enabling offline persistence. Falling back to persistence disabled: Error: ENOENT: no such file or directory, open '/src/protos/google/firestore/v1/firestore.proto'

Is there a way around this, or am I doing something wrong?

Everything appears to be working fine on my local machine when I am developing using npm run dev - including SSR. Hence, this might be an issue related to Netlify-Next.js-Firebase.

I found this post on the Netlify community forums which suggests I am not the only one with the issue. But unlike that user, I am not using Netlify lambdas/functions nor am I used the firebase-admin SDK (server-side library). The resolution from this post is also inconclusive, citing: "Note that even though the write succeeded ... the function did not return a 200 and β€˜Success!’… or a 500. It returned a 502 with a timeout error at the endpoint"

Page chunk for catch-all page at root level is evaluated/rendered on the server

Hello,

First of all thanks for the great work with next-on-netlify, highly appreciated!


What is wrong?

If have a custom app which makes use of SSR via getInitialProps.

pages/_app.jsx:

import React from 'react';
import App from 'next/app';

const MyApp = ({ Component, pageProps, ...customProps }) => {
    return <Component {...pageProps} {...customProps} />;
};

// having a custom app with getInitialProps forces all pages to be rendered on the server
MyApp.getInitialProps = async (ctx) => {
    const appProps = App.getInitialProps(ctx);
    return {
        ...appProps,
        somePropFrom_app: "Hello from the _app"
    };
};

export default MyApp;

Also I have a catch-all page which is used as the index page and as a fallback if there is no matching page for the current route (obviously).

pages/[[...any]].jsx:

import React, { useEffect, useState } from 'react';

export default ({ somePropFrom_app }) => {
    const [ someState, setSomeState ] = useState('waiting for client side code execution...');

    useEffect(() => {
        setSomeState('client side code was executed properly!')
    });

    return (
        <main>
            <p>{somePropFrom_app}</p>
            <p>{someState}</p>
        </main>
    )
}

When I access the catch-all page it is being rendered on the server correctly, but the client side rendering fails. It seems the server sends the rendered HTML instead of the JS source code when the frontend fetches the static JS chunk for this page.

console

When I look at the network tab, I can see that the browser tried to fetch the JS chunk, but received fully rendered HTML instead:

network

As far as I could test it, this seems not to happen for catch-all pages within subdirectories. For example
pages/foo/[[...any]].jsx works as expected.

How to reproduce?

I have set up a minimal repository which reproduces the issue: https://github.com/Yegair/next-on-netlify-minimal.
You can also have a look at the running example here: https://condescending-allen-4992da.netlify.app/

Are there related issues?

This issue may be related to #41 (at least the workaround is the same).

Is there a Workaround?

As I said above, the Workaround from #41 seems to resolve the issue.
Just add a "No-Op redirect" for the /_next/* route:

_redirects:

/_next/* /_next/:splat 200

Add support for getStaticProps and getServerSideProps

Feature request

Full support for the Next 9.3 getStaticProps/getServerSideProps page functions

Is your feature request related to a problem? Please describe.

I recently started deploying a site using next-on-netlify (thank you so much for this plugin, you have saved my team a ton of heartache) and would like to take advantage of getStaticProps, so we can statically generate some content from our CMS at build time.

image

As you can see above, the resources aren't getting generated for the new page types. The pages still load, and has the data generated with SSR, but it's generating the page on demand and not statically at build.

Describe the solution you'd like

Generate pages with getStaticProps as static. Would be happy to help, but am not sure where to start looking.

Describe alternatives you've considered

Accept the outcome but remove the 404 errors by using getInitialProps instead

req.headers.host is undefined on netlify deployment

I'm trying to read the host in getServerSideProps. It works in local environment with
next dev (obviously)
next build && netlify dev

However when deployed on netlify with this plugin,
req.headers.host is undefined. Any info on this? Thank you.

Client-side navigation, react-hook-form and getInitialProps

Hello,

I've been trying to figure this issue out for the last 7 hours or so, so I decided to finally post an issue.

Next-on-netlify has worked great for my site. I use it with Storyblok CMS. Recently with Netlify updates and the new next-on-netlify v2 there are some breaking changes which I have narrowed down to getInitialProps.

I have a Page (Index.tsx) that I export and use on other dynamic routes. If I have getInitialProps on the Index.tsx page, client-side routing with next/link and next/router doesn't work.

I could live without client-side routing but the bigger issue is that I use react-hook-form and the form submission is broken. Rather than handling submission it is posting form values to the URL like a GET request.

Please let me know if I can share more information. I have worked a long time to figure out the issue and I finally narrowed it down to whether or not I use getInitialProps. getStaticProps and getServerSideProps don't seem to have the issue but I'm not sure if they are good replacements. Currently I am using query, req and asPath in getInitialProps and it didn't seem like those values were all available in either getStaticProps or getServerSideProps.

Thanks for any help or suggestions!

Redirect for preview mode

The Next.js samples for preview mode involve doing a redirection from an api route. The code is something like:

  res.setPreviewData({
    maxAge: 60 * 60 // The preview mode cookies expire in 1 hour
  })

  res.writeHead(307, { Location: `/${req.query.contentType}/${req.query.slug}` })

I can do this from next run, but if I try this on Netlify it seems to strip the location header on the 307 redirect. Is this something to do with the compat call or am I doing something wrong?

i18n fails to build

Hello πŸ‘‹

I noticed that I can't build my site when using the new i18n feature. I built dummy repository in which I reproduce the issue.

Page                                                           Size     First Load JS
β”Œ β—‹ /                                                          3.44 kB        65.9 kB
β”œ   /_app                                                      0 B            62.5 kB
β”œ β—‹ /404                                                       3.44 kB        65.9 kB
β”œ Ξ» /api/hello                                                 0 B            62.5 kB
β”” ● /hello                                                     3.45 kB        65.9 kB
+ First Load JS shared by all                                  62.5 kB
  β”œ chunks/f6078781a05fe1bcb0902d23dbbb2662c8d200b3.6d88ef.js  11.4 kB
  β”œ chunks/framework.9116e7.js                                 41.8 kB
  β”œ chunks/main.fa2ed4.js                                      7.99 kB
  β”œ chunks/pages/_app.333f97.js                                529 B
  β”œ chunks/webpack.e06743.js                                   751 B
  β”” css/6e9ef204d6fd7ac61493.css                               194 B

Ξ»  (Lambda)  server-side renders at runtime (uses getInitialProps or getServerSideProps)
β—‹  (Static)  automatically rendered as static HTML (uses no initial props)
●  (SSG)     automatically generated as static HTML + JSON (uses getStaticProps)
   (ISR)     incremental static regeneration (uses revalidate in getStaticProps)


> serverless-i18n@0.1.0 postbuild C:\Users\<user>\Code\serverless-i18n
> next-on-netlify

οΏ½ Next on Netlify οΏ½
   Functions directory: out_functions\
   Publish directory:   out_publish\
   Make sure these are set in your netlify.toml file.
�️ Copying public\ folder to out_publish\
οΏ½ Copying static NextJS assets to out_publish\
οΏ½ Setting up API endpoints as Netlify Functions in out_functions\
   pages/api/hello.js
οΏ½ Setting up pages with getInitialProps as Netlify Functions in out_functions\
οΏ½ Setting up pages with getServerSideProps as Netlify Functions in out_functions\
οΏ½ Copying pre-rendered pages with getStaticProps and JSON data to out_publish\
   /hello
internal/fs/utils.js:298
    throw err;
    ^

Error: ENOENT: no such file or directory, stat '.next\serverless\pages\hello.html'
    at Object.statSync (fs.js:1042:3)
    at Object.statSync (C:\Users\<user>\Code\serverless-i18n\node_modules\graceful-fs\polyfills.js:307:34)
    at statSync (C:\Users\<user>\Code\serverless-i18n\node_modules\fs-extra\lib\util\stat.js:10:52)
    at getStatsSync (C:\Users\<user>\Code\serverless-i18n\node_modules\fs-extra\lib\util\stat.js:24:19)
    at Object.checkPathsSync (C:\Users\<user>\Code\serverless-i18n\node_modules\fs-extra\lib\util\stat.js:49:33)
    at copySync (C:\Users\<user>\Code\serverless-i18n\node_modules\fs-extra\lib\copy-sync\copy-sync.js:24:38)
    at setupStaticFileForPage (C:\Users\<user>\Code\serverless-i18n\node_modules\next-on-netlify\lib\helpers\setupStaticFileForPage.js:11:3)
    at C:\Users\<user>\Code\serverless-i18n\node_modules\next-on-netlify\lib\pages\getStaticProps\setup.js:26:5
    at Array.forEach (<anonymous>)
    at setup (C:\Users\<user>\Code\serverless-i18n\node_modules\next-on-netlify\lib\pages\getStaticProps\setup.js:21:9) {
  errno: -4058,
  syscall: 'stat',
  code: 'ENOENT',
  path: '.next\\serverless\\pages\\hello.html'
}

Te repository that reproduces the issue can be accessed here, just run the following

npm i
npm run build

It is a standard next.js application using:

  • next: 10.0.0
  • next-on-netlify: 2.6.0

Something interesting to note is that the site builds correctly when I omit the getStaticProps in hello.js.

Cannot build if custom distDir is specified

Hey, nice work with this project!

I've noticed that when I specify a distDir different from .next on next.config.js it fails to run the postbuild.

I noticed that NEXT_BUILD_PATH const on next-on-netlify.js is hardcoded to look for .next folder.

Preview: Catch-all page at root level catches requests for NextJS static assets

I have the following (minimal) example:

// pages/api/preview.js
export default async (req, res) => {
  return res.status(404).json({ message: 'Not found' })
}

////////////////////

// pages/index.js
import Link from 'next/link'

function IndexPage() {
  return <Link href='/mypage'><a>My page</a></Link>
}

export async function getStaticProps() {
  return {
    props: {}
  }
}

export default IndexPage

////////////////////

// pages/[...slug].js
const SlugPage = () => {
  return null
}

export async function getStaticProps({params: {slug}}) {
  console.log(`slug = ${slug}`)

  return {
    props: {}
  }
}

export async function getStaticPaths() {
  return {
    paths: [],
    fallback: true
  };
}

export default SlugPage

When I run this example using netlify dev I get an invalid getStaticProps parameter value for slug: _next,static,chunks,pages,[...slug]-0ab994ad29aa8a4f0aaa.js.

The full output is:

β—ˆ Rewrote URL to /.netlify/functions/next_slug
Request from ::1: GET /.netlify/functions/next_slug
info  - Loaded env from .env
[request] /_next/static/chunks/pages/%5B...slug%5D-0ab994ad29aa8a4f0aaa.js
slug = _next,static,chunks,pages,[...slug]-0ab994ad29aa8a4f0aaa.js
Response with status 200 in 225 ms.
Request from ::1: GET /.netlify/functions/next_slug
[request] /_next/data/vAFu7puWIo_lpacbTliex/mypage.json
slug = mypage
Response with status 200 in 54 ms.

Is this a bug?

NB. the <Link> element is necessary to trigger the behaviour.

Local Preview: Static Routes not working

Thanks for the great package!

I set up a brand new default Next.js install and added the code according to README.md

Page                                                           Size     First Load JS
β”Œ β—‹ /                                                          2.31 kB        65.4 kB
β”œ β—‹ /404                                                       3.15 kB        61.3 kB
β”” Ξ» /api/hello
+ First Load JS shared by all                                  58.2 kB
  β”œ static/pages/_app.js                                       954 B
  β”œ chunks/8e104c923a7c97406870fb6411b5f33e5dd2a109.1f6f8d.js  10.5 kB
  β”œ chunks/framework.c6faae.js                                 40 kB
  β”œ runtime/main.9e3c24.js                                     5.97 kB
  β”” runtime/webpack.c21266.js                                  746 B

Ξ»  (Lambda)  server-side renders at runtime (uses getInitialProps or getServerSideProps)
β—‹  (Static)  automatically rendered as static HTML (uses no initial props)
●  (SSG)     automatically generated as static HTML + JSON (uses getStaticProps)

public/_redirects

# Next-on-Netlify Redirects
/index  /_next/pages/index.html  200
/  /_next/pages/index.html  200
/404  /_next/pages/404.html  200
/_error  /.netlify/functions/nextRouter?_path=/_error  200
/api/hello  /.netlify/functions/nextRouter?_path=/api/hello  200

Note that the pages/index.js has no getInitialProps, getServerSideProps, or getStaticProps

The routes under /.netlify/functions works fine (e.g. /api/hello) but the routes pointing to /_next (/, /index, /404) do not work.

After adding getServerSideProps to pages/index.js:

Page                                                           Size     First Load JS
β”Œ Ξ» /                                                          6.97 kB        65.1 kB
β”œ β—‹ /404                                                       3.15 kB        61.3 kB
β”” Ξ» /api/hello
+ First Load JS shared by all                                  58.2 kB
  β”œ static/pages/_app.js                                       954 B
  β”œ chunks/9d5858f224b9f6cb55e0eaaa0a3efae572052440.1f6f8d.js  10.5 kB
  β”œ chunks/framework.c6faae.js                                 40 kB
  β”œ runtime/main.c2a2c7.js                                     5.97 kB
  β”” runtime/webpack.c21266.js                                  746 B

New public/_redirects

# Next-on-Netlify Redirects
/404  /_next/pages/404.html  200
/_error  /.netlify/functions/nextRouter?_path=/_error  200
/api/hello  /.netlify/functions/nextRouter?_path=/api/hello  200
/index  /.netlify/functions/nextRouter?_path=/index  200
/  /.netlify/functions/nextRouter?_path=/  200

The routes /, /index now work fine as they are pointing to the function under /.netlify/functions but /404 still does not work as it's pointing to files under /_next/pages/404.

Broken redirects with optional catch-all route at top-level in pages/

What's wrong

With version 2.4.0 yarn run build produces the following (correct) out_publish/_redirects file:

# Next-on-Netlify Redirects
/api  /.netlify/functions/next_api  200
*  /.netlify/functions/next_any  200

Using 2.5.0 the sorting has changed, and the catch all rules are before the specific ones:

# Next-on-Netlify Redirects
/*  /.netlify/functions/next_any  200
  /.netlify/functions/next_any  200
/api  /.netlify/functions/next_api  200

We can see the /* catch route is before the /api route. Additionally, there is a new (and possible invalid) redirect.

Now the requests to /api are routed to / and the specific handler is not called.

How to reproduce

I created a minimal example repo here: https://github.com/amuttsch/next-on-netlify-minimal

To reproduce just change the version of next-on-netlify in the package.json to 2.4.0 or 2.5.0 and run yarn install && yarn run build.

Thanks for your work on this package!

Can't deploy nextjs on netlify throw new Error(`'${dest}' already exists`) at /opt/build/repo/node_modules/fs-extra/lib/copy-sync/copy-sync.js:62

Hello,
I have followed the instructions in readme.md but got this error

11:18:41 AM: /opt/build/repo/node_modules/fs-extra/lib/copy-sync/copy-sync.js:62 11:18:41 AM: throw new Error('${dest}' already exists) 11:18:41 AM: ^ 11:18:41 AM: Error: 'out_functions/next_glossarium_slug/next_glossarium_slug.js' already exists 11:18:41 AM: at mayCopyFile (/opt/build/repo/node_modules/fs-extra/lib/copy-sync/copy-sync.js:62:11) 11:18:41 AM: at onFile (/opt/build/repo/node_modules/fs-extra/lib/copy-sync/copy-sync.js:54:10) 11:18:41 AM: at getStats (/opt/build/repo/node_modules/fs-extra/lib/copy-sync/copy-sync.js:48:44) 11:18:41 AM: at startCopy (/opt/build/repo/node_modules/fs-extra/lib/copy-sync/copy-sync.js:38:10) 11:18:41 AM: at handleFilterAndCopy (/opt/build/repo/node_modules/fs-extra/lib/copy-sync/copy-sync.js:33:10) 11:18:41 AM: at copySync (/opt/build/repo/node_modules/fs-extra/lib/copy-sync/copy-sync.js:26:10) 11:18:41 AM: at setupNetlifyFunctionForPage (/opt/build/repo/node_modules/next-on-netlify/lib/helpers/setupNetlifyFunctionForPage.js:21:3) 11:18:41 AM: at /opt/build/repo/node_modules/next-on-netlify/lib/pages/getStaticPropsWithFallback/setup.js:21:5 11:18:41 AM: at Array.forEach (<anonymous>) 11:18:41 AM: at setup (/opt/build/repo/node_modules/next-on-netlify/lib/pages/getStaticPropsWithFallback/setup.js:17:9) 11:18:41 AM: npm ERR! code ELIFECYCLE 11:18:41 AM: npm ERR! errno 1 11:18:41 AM: npm ERR! [email protected] postbuild: next-on-netlify 11:18:41 AM: npm ERR! Exit status 1 11:18:41 AM: npm ERR! 11:18:41 AM: npm ERR! Failed at the [email protected] postbuild script. 11:18:41 AM: npm ERR! This is probably not a problem with npm. There is likely additional logging output above. 11:18:41 AM: npm ERR! A complete log of this run can be found in: 11:18:41 AM: npm ERR! /opt/buildhome/.npm/_logs/2020-11-14T04_18_41_667Z-debug.log

anyone having the same problem?

Error during next build: Self-reference dependency has unused export name

Hello, my team currently has a project that's using Netlify to host the production build. However, we've been been getting 404 errors when trying to access the content (it's a dynamic route created when users upload videos.)

We were trying to use next-on-netlify to troubleshoot this issue, but after modifying the config files and updating the build we began receiving this error:

3:46:04 PM: ./node_modules/dom-helpers/cjs/addClass.js
3:46:04 PM: Self-reference dependency has unused export name: This should not happen

This was after receiving several unresolved dependency errors and adding them in an attempt to meet the dependency needs. We're trying to push this project into production soon, but our core issue has ultimately been rendering these dynamic content pages on netlify properly.

Happy to provide more details in an attempt to solve this error.

Build on Netlify takes too long until it timeouts

Building my package locally using yarn build only takes 90 seconds, with the out_functions folder only being 12mb large and out_publish being 68mb.

However, the Netlify deployment process will take a total of 27 mins to complete:

9:19:05 PM: (@netlify/plugin-functions-core onBuild completed in 19m 46.8s)
9:19:05 PM: ​
9:19:05 PM: β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
9:19:05 PM: β”‚ 4. onPostBuild command from netlify-plugin-cache-nextjs β”‚
9:19:05 PM: β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
9:19:05 PM: ​
9:19:07 PM: Cached the .next folder at the location `.next/cache`
9:19:07 PM: ​
9:19:07 PM: (netlify-plugin-cache-nextjs onPostBuild completed in 1.5s)
9:19:07 PM: ​
9:19:07 PM: β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
9:19:07 PM: β”‚   Netlify Build Complete    β”‚
9:19:07 PM: β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
9:19:07 PM: ​
9:19:07 PM: (Netlify Build completed in 24m 45.4s)
9:19:07 PM: Execution timed out after 26m45.2292702s
9:19:07 PM: Error running command: Command did not finish within the time limit
9:19:07 PM: Failing build: Failed to build site
9:19:07 PM: Failed during stage 'building site': Command did not finish within the time limit
9:19:07 PM: Finished processing build request in 27m21.584174186s

Running zip-it-and-ship-it out_functions zipped_functions creates a folder called zipped_functions which is 1.55gb large! It creates 21 zip files (one for each route), each are around 60 - 90 mb each.

Wondering how we can reduce this. As we really want to use Netlify for server-side rendering our NextJS package.

netlify.toml redirects aren't obeyed

Situation: I was trying to allow requests to /random to be proxied to /api/random.

I edited my netlify.toml to add this:

[[redirects]]
  from = "/random" 
  status = 200 # turns the redirect into a proxy
  to = "/api/random"

But ended up getting this output under out_publish/_redirects (i.e. the custom proxy wasn't registered):

# Next-on-Netlify Redirects
/  /.netlify/functions/next_index  200
/api/random  /.netlify/functions/next_api_random  200
/*  /:splat  200

I tried creating a _redirects file instead:

/random /api/random 200

This was being picked up in the output πŸŽ‰

/random /api/random 200!

# Next-on-Netlify Redirects
/  /.netlify/functions/next_index  200
/api/random  /.netlify/functions/next_api_random  200
/*  /:splat  200

However, requests to /random continued to 404. I guessed this was because Netlify only allow one hop. So I changed the contents or _redirects to:

/random /.netlify/functions/next_api_random 200!

...and now it's doing what I want 😁

I don't think there's much we can do about the one-hop limit, but next-on-netlify claims to look at the netlify.toml for redirects, and that doesn't appear to be working πŸ€” is this a bug?

You cannot define a route with the same specificity as a optional catch-all route

I have the following page structure:

Page                              
β”Œ   /_app                       
β”œ ● /[[...rest]]               
β”œ   β”œ /
β”œ   β”” /careers
β”œ β—‹ /404     
β”” Ξ» /api/preview                                     

Command build runs successfully but running next-on-netlify spits out the following error:

Error: You cannot define a route with the same specificity as a optional catch-all route ("/" and "/[[...rest]]").

Unmatched paths return Netlify page

First off, love this project.

I have an issue, but I'm not sure if its this project's responsibility or next in general. In my project, I have a single route that's a fully dynamic route /[businessUnit]/[pageSlug]/[hash] and locally if you hit /, /sales, /sales/qs it returns the error page, but once deployed it shows the Netlify no route found message instead of the error page. Any thoughts on how this should be approached with next-on-netlify?

Error decoding lambda response

error decoding lambda response: error decoding lambda response: json: cannot unmarshal number into Go struct field APIGatewayProxyResponse.multiValueHeaders of type string

Related: https://community.netlify.com/t/error-decoding-lambda-response/16348

This issue started happening a couple days ago when netlify made an unannounced breaking change as seen in the ticket above.

The same repo I used in #9 is now broken without any changes.

Repo:
https://github.com/wei/next-on-netlify-demo-wei

Example:
https://relaxed-mirzakhani-568b34.netlify.app/api/debug/12345
https://relaxed-mirzakhani-568b34.netlify.app/api/debug/12345?testqs=1

I wonder if this is something that should be done in next-on-netlify library or on my side. Any help is appreciated! πŸ™‡

Packaging Functions from out_functions directory never ends?

"Packaging Functions from out_functions directory:" - seems to never end or take very long with Netlify cancelling build...

9:29:51 PM: Packaging Functions from out_functions directory:
9:29:51 PM: - next_createlivefeedback/next_createlivefeedback.js
9:29:51 PM: - next_feedbacksurvey_0introductionpage/next_feedbacksurvey_0introductionpage.js
9:29:51 PM: - next_feedbacksurvey_11corevalues/next_feedbacksurvey_11corevalues.js
9:29:51 PM: - next_feedbacksurvey_12corevalues/next_feedbacksurvey_12corevalues.js
9:29:51 PM: - next_feedbacksurvey_13corevalues/next_feedbacksurvey_13corevalues.js
9:29:51 PM: - next_feedbacksurvey_14corevalues/next_feedbacksurvey_14corevalues.js
9:29:51 PM: - next_feedbacksurvey_2comment/next_feedbacksurvey_2comment.js
9:29:51 PM: - next_feedbacksurvey_31skills/next_feedbacksurvey_31skills.js
9:29:51 PM: - next_feedbacksurvey_32skills/next_feedbacksurvey_32skills.js
9:29:51 PM: - next_feedbacksurvey_33skills/next_feedbacksurvey_33skills.js
9:29:51 PM: - next_feedbacksurvey_34skills/next_feedbacksurvey_34skills.js
9:29:51 PM: - next_feedbacksurvey_35skills/next_feedbacksurvey_35skills.js
9:29:51 PM: - next_feedbacksurvey_36skills/next_feedbacksurvey_36skills.js
9:29:51 PM: - next_feedbacksurvey_4comment/next_feedbacksurvey_4comment.js
9:29:51 PM: - next_feedbacksurvey_completed/next_feedbacksurvey_completed.js
9:29:51 PM: - next_index/next_index.js
9:29:51 PM: - next_knowledgecenter_article/next_knowledgecenter_article.js
9:29:51 PM: - next_knowledgecenter_search/next_knowledgecenter_search.js
9:29:51 PM: - next_mylivefeedback/next_mylivefeedback.js
9:29:51 PM: - next_mytasks/next_mytasks.js
9:29:51 PM: - next_myteam/next_myteam.js
9:29:51 PM: - next_mytools/next_mytools.js
9:29:51 PM: - next_performance_editobjective/next_performance_editobjective.js
9:29:51 PM: - next_performance_myobjectives/next_performance_myobjectives.js
9:29:51 PM: - next_performance_myperformance/next_performance_myperformance.js
9:29:51 PM: - next_performance_newobjective/next_performance_newobjective.js
9:29:51 PM: - next_performance_submitreview/next_performance_submitreview.js
9:29:51 PM: - next_performance_viewobjective/next_performance_viewobjective.js
9:29:51 PM: - next_report_attachments/next_report_attachments.js
9:29:51 PM: - next_report_corevalues/next_report_corevalues.js
9:29:51 PM: - next_report_cover/next_report_cover.js
9:29:51 PM: - next_report_info/next_report_info.js
9:29:51 PM: - next_report_objectives/next_report_objectives.js
9:29:51 PM: - next_report_openquestions/next_report_openquestions.js
9:29:51 PM: - next_report_skills/next_report_skills.js
9:29:51 PM: - next_report_writeup/next_report_writeup.js
9:29:51 PM: - next_selfevaluation_0introductionpage/next_selfevaluation_0introductionpage.js
9:29:51 PM: - next_selfevaluation_11corevalues/next_selfevaluation_11corevalues.js
9:29:51 PM: - next_selfevaluation_12corevalues/next_selfevaluation_12corevalues.js
9:29:51 PM: - next_selfevaluation_13corevalues/next_selfevaluation_13corevalues.js
9:29:51 PM: - next_selfevaluation_14corevalues/next_selfevaluation_14corevalues.js
9:29:51 PM: - next_selfevaluation_21myskills/next_selfevaluation_21myskills.js
9:29:51 PM: - next_selfevaluation_22myskills/next_selfevaluation_22myskills.js
9:29:51 PM: - next_selfevaluation_23myskills/next_selfevaluation_23myskills.js
9:29:51 PM: - next_selfevaluation_24myskills/next_selfevaluation_24myskills.js
9:29:51 PM: - next_selfevaluation_25myskills/next_selfevaluation_25myskills.js
9:29:51 PM: - next_selfevaluation_26myskills/next_selfevaluation_26myskills.js
9:29:51 PM: - next_selfevaluation_31yourobjectives/next_selfevaluation_31yourobjectives.js
9:29:51 PM: - next_selfevaluation_32yourobjectives/next_selfevaluation_32yourobjectives.js
9:29:51 PM: - next_selfevaluation_41performancereview/next_selfevaluation_41performancereview.js
9:29:51 PM: - next_selfevaluation_42performancereview/next_selfevaluation_42performancereview.js
9:29:51 PM: - next_selfevaluation_attachments/next_selfevaluation_attachments.js
9:29:51 PM: - next_selfevaluation_completed/next_selfevaluation_completed.js
9:29:51 PM: - next_skills_myskills/next_skills_myskills.js
....
9:42:31 PM: Canceling deploy
9:42:37 PM: Execution timed out after 17m7.720807482s
9:42:37 PM: Error running command: Command did not finish within the time limit
9:42:37 PM: Failing build: Failed to build site
9:43:07 PM: Failed to inform the API about a failed build, please retry the build or contact support
9:43:07 PM: Finished processing build request in 17m54.632197674s

Set custom function route for Netlify identity hooks

Hi, I was wondering if there is a way to set functions as custom routes that will be picked up by Netlify's identity hooks.

The function that is produced in next-on-netlify:
Screen Shot 2020-10-15 at 5 14 34 PM

What I think Netlify Identity will trigger when someone signs up:
Screen Shot 2020-10-15 at 5 14 50 PM

Looking at the docs:
https://docs.netlify.com/functions/functions-and-identity/#trigger-serverless-functions-on-identity-events

I looked at the issue related to (https://github.com/netlify/next-on-netlify#custom-netlify-functions) but don't know that it is the same need here.

This is a weird question/issue I don't know if it is a feature request or a misunderstanding of how these two things interact. Happy to make this an example and add to docs when I better understand what's going on πŸ˜‚

Adding Support for Custom Netlify Functions

As mentioned in the Readme. I need support for custom netlify functions.
It would at least help to move every thing from "/functions" to the "/out_functions".
Which i will do myself as an Workaround.

running next build and lamba function in same project

I have a netlify-lambda function that generates an api.js file into out_functions and then I run the next build and this erases the contents of the out_functions folder removing my api.s file and populates it with the nextjs functions. Is there anyway to change the folder directory or another way around this to prevent it overwriting my other file?

Error during build step `index.html already exists`

Hi there,

Thanks for the great project!

I've encountered this error while building a prod version of my nextJS app (dev version is fine):

Error: 'out_publish/index.html' already exists

I first saw this in the netlify CI, but was able to reproduce locally too. I have already followed the instructions here.

You can see my repo here, it's a pretty basic setup and definitely doesn't have a spare index.js in the pages directory messing with things :)

Based on the build output, it looks like it is picking up two index.html files to copy

image

But I don't see that in the .next output myself:

image

Deps:

"next-on-netlify": "^2.4.0",
"next": "latest", // evaluated to 9.4.4

Thanks again for your great work, let me know if I can provide any more details to help debug this issue.

Unknown routes should render 404.html

Hi,

Cool project! I was looking for something similar for quite long, and your solution seems to work pretty well!

The current implementation doesn't support rendering of the 404.html file, if an unknown URL is requested. For example, try this link: https://next-on.netlify.com/some-non-existing-url - it should actually render _next/pages/404.html file.

A quick fix that I've found for this problem is to simply copy the 404.html file to public in a post-build step. Something like cp public/_next/pages/404.html public. The reason is that Netlify are expecting to find this file exactly on this place. But I wonder if that's the right solution, or if there are better ways. Another approach that I've tried was to add /* /_next/pages/404.html 404 at the end of _redirects file, but it didn't work very well with netlify-dev.

Would love to hear your thoughts. Thanks :)

Can't resolve 'pnpapi'

I just started using this project but ran into a show stopper when running my build.

12:45:11 PM: > next build
12:45:12 PM: Warning: No build cache found. Please configure build caching for faster rebuilds. Read more: https://err.sh/next.js/no-cache
12:45:12 PM: Creating an optimized production build...
12:45:55 PM: Failed to compile.
12:45:55 PM: 
12:45:55 PM: ./node_modules/next/dist/lib/resolve-request.js
12:45:55 PM: Module not found: Can't resolve 'pnpapi' in '/opt/build/repo/node_modules/next/dist/lib'
12:45:55 PM: > Build error occurred
12:45:55 PM: Error: > Build failed because of webpack errors
12:45:55 PM:     at build (/opt/build/repo/node_modules/next/dist/build/index.js:13:917)
12:45:55 PM:     at process._tickCallback (internal/process/next_tick.js:68:7)
12:45:55 PM: npm
12:45:55 PM:  ERR! code ELIFECYCLE
12:45:55 PM: npm
12:45:55 PM:  ERR! errno
12:45:55 PM:  1
12:45:55 PM: npm
12:45:55 PM: ERR! [email protected] build: `next build`
12:45:55 PM: npm ERR! Exit status 1
12:45:55 PM: npm ERR!
12:45:55 PM: npm ERR!
12:45:55 PM:  Failed at the [email protected] build script.
12:45:55 PM: npm
12:45:55 PM:  ERR! This is probably not a problem with npm. There is likely additional logging output above.
12:45:55 PM: npm
12:45:55 PM:  ERR! A complete log of this run can be found in:
12:45:55 PM: npm ERR!
12:45:55 PM:      /opt/buildhome/.npm/_logs/2020-06-01T18_45_55_956Z-debug.log

I can't seem to get around this, but I'm also at a loss trying to figure out what the issue really is.

I'm running Next 9.4.4 and Node 12/13

Issues with sequelize

I love your guys package and really enjoy using netlify and nextjs with an api.

I've ran into an issue where I can't build using this package when I also am using sequelize. I am wondering if I am able to get some help or possibly contribute to this package to get it working.

ModuleNotFoundError: Module not found: Error: Can't resolve 'pg-native' in '/opt/build/repo/node_modules/pg/lib/native'

I've tried altering my next.config.js to try and work around this errors. It would build locally and on netlify, but fail when creating the netlify functions with the same errors.

module.exports = { // Target must be serverless target: 'serverless', webpack: (config, { webpack }) => { // Note: we provide webpack above so you should not require it // Perform customizations to webpack config config.plugins.push(new webpack.IgnorePlugin(/\/__tests__\//)); config.externals = [ ...config.externals, 'pg', 'sqlite3', 'tedious', 'pg-hstore', ]; // Important: return the modified config return config; }, };

{ "name": "with-typescript", "version": "1.0.0", "scripts": { "dev": "next", "build": "next build", "start": "next start", "postbuild": "next-on-netlify", "type-check": "tsc" }, "dependencies": { "@material-ui/core": "^4.11.0", "@material-ui/icons": "^4.9.1", "@types/lodash": "^4.14.159", "@types/nodemailer": "^6.4.0", "@types/sequelize": "^4.28.9", "axios": "^0.19.2", "babel-plugin-react-intl": "^8.1.1", "lodash": "^4.17.19", "netlify-plugin-cache-nextjs": "^1.5.0", "next": "latest", "next-on-netlify": "^2.3.2", "nodemailer": "^6.4.11", "notistack": "^0.9.17", "pg": "^8.3.0", "pg-hstore": "^2.3.3", "react": "^16.13.1", "react-dom": "^16.12.0", "react-intl-hooks": "^1.0.11", "sequelize": "^6.3.4" }, "devDependencies": { "@types/node": "^12.12.21", "@types/pg": "^7.14.4", "@types/react": "^16.9.46", "@types/react-dom": "^16.9.8", "typescript": "^3.9.7" }, "license": "ISC" }

I've tried to create the sequelize connection multiple different ways but build is always failing. Here is what I have currently:

const sequelize = new Sequelize({ database, username, password, port, host: process.env.HOST, protocol: 'postgres', dialect: 'postgres', dialectModule: require('pg'), dialectOptions: { ssl: { rejectUnauthorized: false, }, }, logging: false, });

Any help on this issue would be incredible. Thank you!

Request: allow `out_functions`/`out_publish` directory names to be configurable

I spent quite some time editing my netlify.toml, trying to consolidate the outputs into one folder with subfolders, i.e.:

[build]
  command = "npm run build"
  functions = "out/functions"
  publish = "out/publish"

I ran npm run build and was confused that it would still output to out_functions and out_publish folders. Then I realised these are hard-coded and cannot be configured.

Could we make this configurable? If not, could we make it clearer in the README that these are fixed directory names?

Prisma does not seem to get rhel binary in functions

I've been following this example and it works on "standard netlify" : https://github.com/garrypolley/deployment-example-netlify

I'm attempting to use next as well on a private site API ID: c076fc19-1890-4dd6-b610-1b57342b8c39

Whenever any attempt to query the database is made I get the following error:

Query engine binary for current platform "rhel-openssl-1.0.x" could not be found.
This probably happens, because you built Prisma Client on a different platform.
(Prisma Client looked in "/query-engine-rhel-openssl-1.0.x")

Files in /:

  bin
  boot
  dev
  etc
  home
  lib
  lib64
  media
  mnt
  opt
  proc
  root
  run
  sbin
  srv
  sys
  tmp
  usr
  var

You already added the platforms "native", "rhel-openssl-1.0.x" to the "generator" block
in the "schema.prisma" file as described in https://pris.ly/d/client-generator,
but something went wrong. That's suboptimal.

Please create an issue at https://github.com/prisma/prisma-client-js/issues/new

I believe this is because the rhel binary is not shipping inside the bundled function that goes in the out_functions directory.

I've tried a lot of options:

  • bundling the primsa client in my own code -- still misses the rhel binary
  • copying over the binary to each of the output directories in a custom build plugin -- still misses the same error

I think if the rhel binary can be found on the running lambda disk then this environment variable could be set and it'd work PRISMA_QUERY_ENGINE_BINARY

There are a few issues logged for this across Netlify and Primsa githubs. And also a community post as well https://community.netlify.com/t/prisma-client-binary-not-copied-for-netlify-lambda-functions-for-graphql-server/11701

I'm happy to help troubleshoot further.

Root redirects to 404 when deploying / running netlify dev

Don't know exactly if this is next-on-netlify issue or if it's related to netlify-cli.

Basically after running dev version on localhost or even deploying to netlify and visiting served page, you are automatically redirected to 404.

Here is how I managed to encounter a problem:

  1. Cloning https://github.com/FinnWoelm/next-on-netlify-demo
  2. Installing npm packages
  3. npm run build
  4. netlify dev

Visiting any page over URL directly (except index) works as expected, even navigation over all pages after works normally. The only problem is direct visit to /.

Anyone else experiencing this?

Run tests on Node `10.13.0`

Node 10.13.0 is the minimal version supported by Next.js 9/10.
However, the CI tests currently run Node 10.17.0. They should run 10.13.0 instead.

Functions fail when using Firebase Admin SDK

Functions fail when using Firebase Admin SDK.
When I am requesting data from firestore using firebase admin SDK, I get this error:

(node:14684) Warning: protos.json not found in any of the include paths \protos,\protos
(Use node --trace-warnings ... to show where the warning was created)
Error: ENOENT: no such file or directory, open 'protos.json'
at Object.openSync (fs.js:466:3)
at Object.readFileSync (fs.js:369:35)

Can this be fixed?
Currently the admin SDK is not usable on the functions and getServerSideProps

P.S. Locally works just fine when running next dev but fails when running next build && next start

Support for Next/Image

Hello everyone, as you might already know Next now has a new Image Component and I was thinking if its possible to support it on Netlify ?

At our company we are very tight with the whole Netlify ecosystem, we use Netlify CMS and we use Netlify for publishing almost everything that we have & we cant afford to switch to Vercel just for this component.

The new Image component is very good but sadly I found out that they only support that on Vercel hosted sites, We are not very familiar with next-on-netlify thus we can't do a PR, but we are willing to help out during the PR with testing, docs, or whatever is needed.

Thank you

Redirects returned from getServerSideProps are not obeyed 😒

Hi!

I've got a Next app on Netlify and it works amazing! Thank you for your great work! I've had no problems thus far, except with the following syntax:

export const getServerSideProps: GetServerSideProps = async ({ req, res }) => {
  const auth = await authenticate({ req, res });

  if (!auth.isLoggedIn) {
    return { redirect: { destination: loginRoute, permanent: false } };
  }

  const { currentUser, access } = auth;

  const events = await getEvents();

  return {
    props: {
      currentUser,
      events,
    },
  };
};

Which returns the error on Netlify:

1:05:13 PM: 2020-11-15T12:05:13.456Z	0d58c161-5d0b-4a41-9724-a1b67fee275f	INFO	[request] /scheduling
1:05:13 PM: 2020-11-15T12:05:13.600Z	0d58c161-5d0b-4a41-9724-a1b67fee275f	ERROR	Unhandled error during request: TypeError [ERR_INVALID_ARG_TYPE]: The "string" argument must be of type string or an instance of Buffer or ArrayBuffer. Received null
    at Function.byteLength (buffer.js:726:11)
    at sendPayload (/var/task/src/out_functions/next_scheduling/nextJsPage.js:21039:844)
    at renderReqToHTML (/var/task/src/out_functions/next_scheduling/nextJsPage.js:16899:15)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async Module.render (/var/task/src/out_functions/next_scheduling/nextJsPage.js:16969:22) {
  code: 'ERR_INVALID_ARG_TYPE'
}
1:05:13 PM: 2020-11-15T12:05:13.600Z	0d58c161-5d0b-4a41-9724-a1b67fee275f	ERROR	TypeError [ERR_INVALID_ARG_TYPE]: The "string" argument must be of type string or an instance of Buffer or ArrayBuffer. Received null
    at Function.byteLength (buffer.js:726:11)
    at sendPayload (/var/task/src/out_functions/next_scheduling/nextJsPage.js:21039:844)
    at renderReqToHTML (/var/task/src/out_functions/next_scheduling/nextJsPage.js:16899:15)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async Module.render (/var/task/src/out_functions/next_scheduling/nextJsPage.js:16969:22) {
  code: 'ERR_INVALID_ARG_TYPE'
}
1:05:13 PM: 2020-11-15T12:05:13.601Z	0d58c161-5d0b-4a41-9724-a1b67fee275f	ERROR	Unhandled Promise Rejection 	{"errorType":"Runtime.UnhandledPromiseRejection","errorMessage":"TypeError [ERR_INVALID_ARG_TYPE]: The \"string\" argument must be of type string or an instance of Buffer or ArrayBuffer. Received null","reason":{"errorType":"TypeError","errorMessage":"The \"string\" argument must be of type string or an instance of Buffer or ArrayBuffer. Received null","code":"ERR_INVALID_ARG_TYPE","stack":["TypeError [ERR_INVALID_ARG_TYPE]: The \"string\" argument must be of type string or an instance of Buffer or ArrayBuffer. Received null","    at Function.byteLength (buffer.js:726:11)","    at sendPayload (/var/task/src/out_functions/next_scheduling/nextJsPage.js:21039:844)","    at renderReqToHTML (/var/task/src/out_functions/next_scheduling/nextJsPage.js:16899:15)","    at processTicksAndRejections (internal/process/task_queues.js:97:5)","    at async Module.render (/var/task/src/out_functions/next_scheduling/nextJsPage.js:16969:22)"]},"promise":{},"stack":["Runtime.UnhandledPromiseRejection: TypeError [ERR_INVALID_ARG_TYPE]: The \"string\" argument must be of type string or an instance of Buffer or ArrayBuffer. Received null","    at process.<anonymous> (/var/runtime/index.js:35:15)","    at process.emit (events.js:315:20)","    at processPromiseRejections (internal/process/promises.js:209:33)","    at processTicksAndRejections (internal/process/task_queues.js:98:32)"]}
1:05:13 PM: [ERROR] [1605441913603] LAMBDA_RUNTIME Failed to post handler success response. Http response code: 403.
1:05:13 PM: Duration: 153.22 ms	Memory Usage: 94 MB	Init Duration: 401.18 ms	
1:05:13 PM: RequestId: 0d58c161-5d0b-4a41-9724-a1b67fee275f Error: Runtime exited with error: exit status 128
Runtime.ExitError

The real frustrating thing is – this works great locally when running next dev, and even works great when running a site built with next-on-netlify via netlify-cli, but breaks when actually deployed to Netlify. This is visible here.

I'd love to help out and make a PR to fix this if possible. If the issue isn't on this project, but is a general flaw with Netlify Functions, I apologize. I tried to find the best place to report this and this repo seemed ideal.

Client-side routing not working

Hello! Thanks for all your hard work on this project.

Before V2 I used client-side routing but now I find that the links are not working. This applies to next/link as well as next/router.

Please let me know if there is any more information I can provide or anything I can do to help.

Why are Pre-rendered HTML or SSG pages given an entry in the _redirects file?

The Netlify platform does file shadowing, where the static file is delivered first regardless:
https://docs.netlify.com/routing/redirects/rewrites-proxies/#shadowing

Example in _redirects:
/health/en/kids/emily-story/article /health/en/kids/emily-story/article.html 200

I ask, because we are pre-rendering + SSG many thousands (15,000+) of pages. So the _headers files has an entry for each. Also, the console log prints a line for each during build.

Support for target: 'experimental-serverless-trace'

Can you also add for target: 'experimental-serverless-trace'.
I'm using firebase, but the build returns an error:

Build error occurred
Error: ENOENT: no such file or directory, open 'google/protobuf/api.proto'

Previously used, target: 'serverless' is going to be deprecated.

Reference: vercel/next.js#11860

Accessing public folder files?

Hi there.
I'm using next-i18next for translations. The locale files are stored in public/translations.
As far as I know, Next automatically servers the public folder, and it should have access to it!
When I deploy the project to Netlify, it seems the application does not have access to files. This is the error that shows me:

{
  "errorType": "Error",
  "errorMessage": "ENOENT: no such file or directory, scandir '/var/task/public/translations/en'",
  "trace": [
    "Error: ENOENT: no such file or directory, scandir '/var/task/public/translations/en'",
    "    at Object.readdirSync (fs.js:948:3)",
    "    at getAllNamespaces (/var/task/src/out_functions/next_index/nextJsPage.js:124241:19)",
    "    at createConfig (/var/task/src/out_functions/next_index/nextJsPage.js:124246:27)",
    "    at new NextI18Next (/var/task/src/out_functions/next_index/nextJsPage.js:158492:48)",
    "    at Object.0v6L (/var/task/src/out_functions/next_index/nextJsPage.js:5428:18)",
    "    at __webpack_require__ (/var/task/src/out_functions/next_index/nextJsPage.js:31:31)",
    "    at Module.cha2 (/var/task/src/out_functions/next_index/nextJsPage.js:105080:15)",
    "    at __webpack_require__ (/var/task/src/out_functions/next_index/nextJsPage.js:31:31)",
    "    at Module.rxt/ (/var/task/src/out_functions/next_index/nextJsPage.js:146697:17)",
    "    at __webpack_require__ (/var/task/src/out_functions/next_index/nextJsPage.js:31:31)"
  ]
}

Note: the application works fine in Development and Production (next build & next start).

Static HTML Export

While this project solves pretty much everything I would need from a product point of view, the fact it heavily relies on Netlify functions - even for routes that could benefit from static exporting - makes the outcome potentially expensive once you reach Netlify's limits for function execution.

I'm wondering if it would be possible easily combine the benefits of both approaches. The idea would be to reuse next export results, and then adapt next-on-netlify redirects so those direct paths to statically exported HTML can be used as is, with no function related to it - while still fall-backing to the serverless route when reaching a non-built route.

This could potentially reduce build time - my project went from 3m to 7m after installing this package - and highly decrease usage costs overall.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.