jonahsnider / netlify-cache-nextjs

Cache the Next.js build folder in your Netlify builds
https://www.npmjs.com/package/netlify-plugin-cache-nextjs
58 stars 6 forks source link

No cache found #95

Closed jonahsnider closed 3 years ago

jonahsnider commented 4 years ago

We are currently getting this issue under the same circumstances -- we have the package included in our netlify.toml and that is all we have done. We are using next-on-netlify to enable serverless functions if that is relevant. Is there any further discovery as to what resolved this?


I did not previously have the plugin installed in Netlify itself, just declared in our repo -- is this necessary? this was not clear from the docs.

However, I am still receiving the message.


and one last thing -- similarly, locally it appears to work (on second build)

$ netlify build --context=deploy-preview
...
┌────────────────────────────────────────────────────────┐
│ 1. onPreBuild command from netlify-plugin-cache-nextjs │
└────────────────────────────────────────────────────────┘

.next/cache exists on disk
Restored the cached .next folder at the location `.next/cache`

(netlify-plugin-cache-nextjs onPreBuild completed in 323ms)

Originally posted by @pmourer in https://github.com/pizzafox/netlify-cache-nextjs/issues/80#issuecomment-686785436

issue-label-bot[bot] commented 4 years ago

Issue Label Bot is not confident enough to auto-label this issue. See dashboard for more details.

jonahsnider commented 4 years ago

The previous issue was never really properly resolved, it stopped occurring after a few days without change. The plugin hasn't changed since then, and since it works locally and on other Netlify builds I'm (still) inclined to believe this is an upstream issue with Netlify's library or infrastructure.

That makes me think this is a Netlify side issue. Try sending them a support request and feel free to include me in the ticket. My email is jonah@jonah.pw.

jonahsnider commented 4 years ago

IIRC their Zendesk will email you shortly after filling out their form.

jonahsnider commented 4 years ago

Hmm, I'll do a bit of testing with my repo and see what I find.

moop-moop commented 4 years ago

We are only using the Netlify installed configuration-less setup (not in netlify.toml) and are not seeing this problem. Last build (node 12.16.2):

9:45:30 AM: ❯ Config file
9:45:30 AM:   /opt/build/repo/netlify.toml
9:45:30 AM: ​
9:45:30 AM: ❯ Context
9:45:30 AM:   production
9:45:30 AM: ​
9:45:30 AM: ❯ Loading plugins
9:45:30 AM:    - netlify-plugin-cache-nextjs@1.4.0 from Netlify app
9:45:30 AM:    - @netlify/plugin-sitemap@0.3.4 from Netlify app
9:45:30 AM:    - netlify-plugin-contextual-env@0.3.0 from Netlify app
9:45:30 AM:    - @uwhealth/netlify-plugin-jest@1.0.0 from netlify.toml and package.json
9:45:32 AM: ​
9:45:32 AM: ┌────────────────────────────────────────────────────────┐
9:45:32 AM: │ 1. onPreBuild command from netlify-plugin-cache-nextjs │
9:45:32 AM: └────────────────────────────────────────────────────────┘
9:45:32 AM: ​
9:45:32 AM: Restored the cached .next folder at the location `.next/cache`
9:45:32 AM: ​
9:45:32 AM: (netlify-plugin-cache-nextjs onPreBuild completed in 412ms)
moop-moop commented 4 years ago

We are not using next-on-netlify in this repo, but we are in another, so I will check that one too.

jonahsnider commented 4 years ago

Yeah uhhhh my personal website is also using 1.4.0 (which is outdated, 1.5.0 was released a month ago), will investigate further.

moop-moop commented 4 years ago

We are not using next-on-netlify in this repo, but we are in another, so I will check that one too.

Build with next-on-netlify library also ok. Also using netlify.com installed plugin.

9:22:54 AM: ❯ Version
9:22:54 AM:   @netlify/build 3.3.5
9:22:54 AM: ​
9:22:54 AM: ❯ Flags
9:22:54 AM:   deployId: *
9:22:54 AM:   mode: buildbot
9:22:54 AM: ​
9:22:54 AM: ❯ Current directory
9:22:54 AM:   /opt/build/repo
9:22:54 AM: ​
9:22:54 AM: ❯ Config file
9:22:54 AM:   /opt/build/repo/netlify.toml
9:22:54 AM: ​
9:22:54 AM: ❯ Context
9:22:54 AM:   production
9:22:54 AM: ​
9:22:54 AM: ❯ Loading plugins
9:22:54 AM:    - @netlify/plugin-sitemap@0.3.4 from Netlify app
9:22:54 AM:    - netlify-plugin-contextual-env@0.3.0 from Netlify app
9:22:54 AM:    - netlify-plugin-cache-nextjs@1.5.0 from netlify.toml and package.json
9:22:55 AM: ​
9:22:55 AM: ┌──────────────────────────────────────────────────────────┐
9:22:55 AM: │ 1. onPreBuild command from netlify-plugin-contextual-env │
9:22:55 AM: └──────────────────────────────────────────────────────────┘
9:22:55 AM: ​
9:22:56 AM: Exporting URL=https://***.
9:22:56 AM: Exporting PATHS_FILE_NAME=paths.js.
9:22:56 AM: Replaced 2 ENVs
9:22:56 AM: ​
9:22:56 AM: (netlify-plugin-contextual-env onPreBuild completed in 6ms)
9:22:56 AM: ​
9:22:56 AM: ┌────────────────────────────────────────────────────────┐
9:22:56 AM: │ 2. onPreBuild command from netlify-plugin-cache-nextjs │
9:22:56 AM: └────────────────────────────────────────────────────────┘
9:22:56 AM: ​
9:22:56 AM: .next/cache exists on disk
9:22:56 AM: Restored the cached .next folder at the location `.next/cache`
9:22:56 AM: ​
9:22:56 AM: (netlify-plugin-cache-nextjs onPreBuild completed in 321ms)
moop-moop commented 4 years ago

Yeah uhhhh my personal website is also using 1.4.0 (which is outdated, 1.5.0 was released a month ago), will investigate further.

https://github.com/netlify/plugins/blob/master/docs/CONTRIBUTING.md#update-a-plugin

Seems to be older 1.4 version in the Netlify directory:

https://github.com/netlify/plugins/blob/master/plugins.json

jonahsnider commented 4 years ago

????????????????????????????? Why is that a thing?

moop-moop commented 4 years ago

do you have this plugin in package.json locked at a specific version?

Yes, apparently the second repo/project I mentioned is installed with 1.5 and configured in the netlify.toml. It is ALSO configured to use the netlify.com configuration-less plugin. :man_facepalming:

Well I guess having both is not an issue....

jonahsnider commented 4 years ago

Ok, I think I've figured it out.

Looking at the logs of someone who wanted to have their plugin added to Netlify's list I saw this line:

netlify-plugin-cache@1.0.1 from netlify.toml and package.json

Try adding the plugin as a devdependency to your project and Netlify should load that version. I just tested on my own Next.js site and it used version 1.5.0. If the issue goes away after using 1.5.0 then I will mark this as closed.

yarn add -D netlify-plugin-cache-nextjs
npm install -D netlify-plugin-cache-nextjs
jonahsnider commented 4 years ago

I truly have no idea why this is happening. It works on my site, we're all running the latest version of the plugin.

I'm going to try doing some random refactoring in the hopes it fixes it (it probably won't).

Edit: published v1.5.1

jonahsnider commented 4 years ago

I am testing in a production context, deploy previews eat up my build minutes.

moop-moop commented 4 years ago

We have build minutes, I will check out various open PRs that use the plugin.

moop-moop commented 4 years ago

We have build minutes, I will check out various open PRs that use the plugin.

Our deploy-previews are restoring the cache on both projects that use the plugin (one on version 1.4, the other 1.5).

moop-moop commented 4 years ago

When I was seeing what seems like the same unexplained issue late July, I had cases where simply commiting to the branch (used in the PR) caused the cache to be restored all of sudden. Almost like the specific commit itself was broken.

moop-moop commented 4 years ago

When I was seeing what seems like the same unexplained issue late July, I had cases where simply commiting to the branch (used in the PR) caused the cache to be restored all of sudden. Almost like the specific commit itself was broken.

And creating a new commit resolved the block.

jonahsnider commented 4 years ago

If anyone could try giving a reproducible site that would be great. I'm not sure if this is a Next.js issue, a Netlify bug, or some weird behavior Netlify does.

Michael-Reich commented 3 years ago

Same problem, could not found a solution:

netlify.toml

[build]
  command   = "npm run build"
  functions = "out_functions"
  publish   = "out_publish"
[[plugins]]
  package = "netlify-plugin-cache-nextjs"

next.config.js

// next.config.js
const path = require('path')

module.exports = {
  // Target must be serverless
  target: 'serverless',
  sassOptions: {
    includePaths: [path.join(__dirname, 'styles')],
  },
};

package.json

{
  "name": "",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next-boost",
    "postbuild": "next-on-netlify",
    "lint": "eslint ./components/** ./pages/** -c .eslintrc.js --ext js,jsx",
    "lint-fix": "eslint ./components/** ./pages/** -c .eslintrc.js --fix --ext js,jsx"
  },
  "dependencies": {
    "@socialgouv/matomo-next": "^1.1.2",
    "axios": "^0.20.0",
    "bootstrap": "^4.5.3",
    "next": "9.5.5",
    "next-boost": "^0.7.7",
    "next-on-netlify": "^2.5.1",
    "react": "17.0.0",
    "react-awesome-slider": "^4.1.0",
    "react-bootstrap": "^1.4.0",
    "react-dom": "17.0.0",
    "react-lazyload": "^3.1.0",
    "react-shufflejs": "^0.2.0",
    "react-slick": "^0.27.12",
    "sass": "^1.27.0",
    "shufflejs": "^5.2.3",
    "slick-carousel": "^1.8.1",
    "storyblok-js-client": "^3.1.1",
    "storyblok-react": "^0.1.1"
  },
  "devDependencies": {
    "eslint": "^7.12.0",
    "eslint-plugin-react": "^7.21.5",
    "netlify-plugin-cache-nextjs": "^1.5.2"
  }
}
oliviertassinari commented 3 years ago

This is an issue with Netlify: https://github.com/netlify/build-image/issues/480.

jonahsnider commented 3 years ago

Is it possible that this caching will not work for deploy-previews?

@pmourer called it 2 months back. I should have done a better job testing and have figured out specifically what was wrong. Glad that this is getting resolved soon.

oliviertassinari commented 3 years ago

I'm not sure it will be resolved soon. The issue has been stale for a long time, nor it seems to have received a lot of upvotes. On our side, this would save 5min of build. The large majority of our builds are previews.

kaganjd commented 3 years ago

👋🏻 Netlify Support here- I found this issue linked to https://github.com/netlify/build-image/issues/480 - that issue should now be resolved thanks to change that rolled out on Tuesday to how we do Deploy Preview caching. Check out https://community.netlify.com/t/build-cache-is-now-updated-in-deploy-preview-builds/26344 for more details

jonahsnider commented 3 years ago

Fix has been released for a week now, issue should be resolved.

jorisw commented 3 years ago

It is, but I did have to 'tickle' my build with an actual commit, rather than a Retry Deploy, for the cache written by the first deploy to be picked up by the second.