Skip to content

isStaticExport logic fails if the build command doesn't contain "next export" #503

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
alexshyba opened this issue Jul 8, 2021 · 4 comments · Fixed by #505
Closed

isStaticExport logic fails if the build command doesn't contain "next export" #503

alexshyba opened this issue Jul 8, 2021 · 4 comments · Fixed by #505
Labels
priority: high type: bug code to address defects in shipped code

Comments

@alexshyba
Copy link

alexshyba commented Jul 8, 2021

This is borderlining between a bug and feature request :)

Describe the bug
We had the plugin start failing recently. What ended up happening is that the isStaticExport wasn't detected anymore.

const isStaticExport = usesBuildCommand({ build, scripts, command: "next export" })

To Reproduce
Steps to reproduce the behavior:

  1. Add "build: next build" and "export: next export" to your package.json.
  2. Specify this as your Netlify build command as "netlify:build": "npm run build && npm run export"
  3. Run build and notice that the static export wasn't detected.

This is due to "next export" not found in the build command string.

Expected behavior

This could be a fragile way of detecting whether the plugin should run or not. Since there doesn't seem to be a way to opt out of the plugin install, I think it's worth reviewing the approach here.

Option 1: Provide more flexibility to detect the static build
Option 2: Provide a way to opt out of having the plugin to auto-install at all (I think many will prefer having this option in an env var or something)

Versions

  • Next.js: 11.0.1
  • plugin (if installed at fixed version): 3.6.3
@ascorbic
Copy link
Contributor

ascorbic commented Jul 9, 2021

Well found! That's a really good point: we need a more robust way of detecting which scripts are run. I'll look at that today. The addition of an env var to disable all plugin auto install is a really good idea too. I'll raise that with the team.

@alexshyba
Copy link
Author

hi @ascorbic, looks like the issue is back for us in 4.0.0, breaking all our sites :)
We are using SSG mode and a custom npm run export script:

[build]
  command = 'npm run export'
  publish = 'out'

package.json:

 "export": "next build && next export",

The problem is that the next.js plugin is auto-installed and breaks the build with this:

4:35:37 PM: ────────────────────────────────────────────────────────────────
4:35:37 PM:   4. @netlify/plugin-nextjs (onBuild event)                     
4:35:37 PM: ────────────────────────────────────────────────────────────────
4:35:37 PM: ​
4:35:38 PM: ​
4:35:38 PM: ────────────────────────────────────────────────────────────────
4:35:38 PM:   Plugin "@netlify/plugin-nextjs" failed                        
4:35:38 PM: ────────────────────────────────────────────────────────────────
4:35:38 PM: ​
4:35:38 PM:   Error message
4:35:38 PM:   Error: The directory "out" does not contain a Next.js production build. Perhaps the build command was not run, or you specified the wrong publish directory.
4:35:38 PM:   Your publish directory is set to "out", but in most cases it should be ".next".
4:35:38 PM:   If you are using "next export" then the Essential Next.js plugin should be removed. See https://ntl.fyi/remove-plugin for details.

Is there a way to make sure that the plugin doesn't auto-install?

@ascorbic
Copy link
Contributor

Good point. There isn't a way to disable auto-install, but I could add an env var to disable everything except caching. Would that work for you?

@alexshyba
Copy link
Author

@ascorbic that would be amazing, thanks, Matt!
as a workaround, I had to pin the version of the plugin to v3, which is not a good long term solution :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: high type: bug code to address defects in shipped code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants