Closed
Description
next-on-netlify
requires next
as a peerDependency:
This repository requires next-on-netlify
as a production dependency:
If a site is using this plugin, but forgot to install next
, this plugin will thrown when being require()
'd, as opposed to when onPreBuild
is run. This results in an error message which might be confusing:
Uncaught Error: Cannot find module 'next/constants'
Require stack:
- /home/ether/Desktop/node_modules/next-on-netlify/lib/helpers/getNextDistDir.js
- /home/ether/Desktop/node_modules/next-on-netlify/lib/config.js
- /home/ether/Desktop/node_modules/next-on-netlify/lib/steps/prepareFolders.js
- /home/ether/Desktop/node_modules/next-on-netlify/index.js
- /home/ether/Desktop/node_modules/@netlify/plugin-nextjs/index.js
- <repl>
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:900:15)
at Function.Module._load (node:internal/modules/cjs/loader:745:27)
at Module.require (node:internal/modules/cjs/loader:972:19)
at require (node:internal/modules/cjs/helpers:88:18) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/home/ether/Desktop/node_modules/next-on-netlify/lib/helpers/getNextDistDir.js',
'/home/ether/Desktop/node_modules/next-on-netlify/lib/config.js',
'/home/ether/Desktop/node_modules/next-on-netlify/lib/steps/prepareFolders.js',
'/home/ether/Desktop/node_modules/next-on-netlify/index.js',
'/home/ether/Desktop/node_modules/@netlify/plugin-nextjs/index.js',
'<repl>'
]
}
To fix this:
next
andnext-on-netlify
should berequire()'d
only inside theif (isNextProject) { ... }
block_isNextProject()
should try torequire('next')
, and returnfalse
if that throws an error
We might want to also wonder: are we ok with this plugin requiring users to install Next.js as a dependency (as opposed to doing it for them)?