Skip to content

Plugin load if next is not available #8

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
ehmicky opened this issue Oct 27, 2020 · 5 comments
Closed

Plugin load if next is not available #8

ehmicky opened this issue Oct 27, 2020 · 5 comments
Assignees
Labels
proj/non/next-on-netlify-enterprise type: bug code to address defects in shipped code

Comments

@ehmicky
Copy link

ehmicky commented Oct 27, 2020

next-on-netlify requires next as a peerDependency:

https://github.com/netlify/next-on-netlify/blob/7d1fd5e08969455035bf9918a6fb2d707984c4a1/package.json#L37-L39

This repository requires next-on-netlify as a production dependency:

https://github.com/netlify/netlify-plugin-nextjs/blob/ef4529016ed0f87ae89d5f312dc8f8f08d1ef7b6/package.json#L24-L29

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 and next-on-netlify should be require()'d only inside the if (isNextProject) { ... } block
  • _isNextProject() should try to require('next'), and return false 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)?

@ehmicky ehmicky added the type: bug code to address defects in shipped code label Oct 27, 2020
@lindsaylevine
Copy link

fair enough, happy to add this! but also would be very confused if a next app didnt have next installed, they wouldnt be able to develop their app locally unless they weirdly had next globally installed

@ehmicky
Copy link
Author

ehmicky commented Nov 5, 2020

This is reported on Bugsnag as well.

@ehmicky
Copy link
Author

ehmicky commented Nov 11, 2020

Related to #25

@ehmicky
Copy link
Author

ehmicky commented Nov 16, 2020

See also #25 (comment)

@ehmicky
Copy link
Author

ehmicky commented Nov 17, 2020

Fixed by #45

@ehmicky ehmicky self-assigned this Nov 17, 2020
@ehmicky ehmicky closed this as completed Dec 18, 2020
serhalp pushed a commit that referenced this issue Apr 5, 2024
feat: use none bundler and node_modules created at build time
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proj/non/next-on-netlify-enterprise type: bug code to address defects in shipped code
Projects
None yet
Development

No branches or pull requests

2 participants