Skip to content

Remove npm install next-on-netlify #10

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 · 7 comments · Fixed by #51
Closed

Remove npm install next-on-netlify #10

ehmicky opened this issue Oct 27, 2020 · 7 comments · Fixed by #51
Assignees
Labels
proj/non/next-on-netlify-enterprise type: feature code contributing to the implementation of a feature and/or user facing functionality

Comments

@lindsaylevine
Copy link

@ehmicky this is a bug jason and i discovered monday night. without running the command on line 31, the function bundling errors out because it's unable to find next-on-netlify dependencies.

@ehmicky
Copy link
Author

ehmicky commented Oct 28, 2020

If next-on-netlify is a dependency of this plugin, calling require('next-on-netlify') should work.
Which error message did you get?

@lindsaylevine
Copy link

cannot find module next-aws-lambda traced to one of the generated functions by next-on-netlify. do you mean like a plain require('next-on-netlify') at the top of the file separate from const nextOnNetlify = require('next-on-netlify');?

@ehmicky ehmicky self-assigned this Nov 10, 2020
@ehmicky ehmicky changed the title Remove npm install next-on-netlify? Remove npm install next-on-netlify Nov 10, 2020
@ehmicky
Copy link
Author

ehmicky commented Nov 11, 2020

Related: netlify/next-on-netlify#56

The problem is the following.
next-on-netlify is copying Next.js serverless files to the Netlify Functions directory, renaming each of them to nextJsPage.js then wrapping them with the following small file.
That wrapper file requires next-aws-lambda:

https://github.com/netlify/next-on-netlify/blob/a48735f625cc7ad1a080b322673d3e9a11f42d27/lib/templates/netlifyFunction.js#L5

When zip-it-and-ship-it bundles Netlify Functions, we look for Functions dependencies in the site's node_modules. We do not look for them in each plugin's node_modules (which is a separate directory). Therefore, in order to bundle the above Functions correctly, next-aws-lambda must be available in the site's dependencies.

The above workaround works because next-aws-lambda is a direct dependency of next-on-netlify:

https://github.com/netlify/next-on-netlify/blob/a48735f625cc7ad1a080b322673d3e9a11f42d27/package.json#L56

However, there is no need for the site to install all of next-on-netlify to make this work. Installing only next-aws-lambda should work, and would be faster.

That being said, running npm install next-on-netlify is not an optimal solution. It makes this plugin much slower. It might make the build fail (npm install fails actually fairly often in our build system). It might not work for Yarn users. The real solution here would be for next-on-netlify to bundle Functions (as opposed to rely on zip-it-and-ship-it) as suggested by @erezrokah in this comment and make sure next-aws-lambda is included during bundling.

I would suggest the two following action points to solve this issue:

  1. First, as a temporary improvement, replace npm install next-on-netlify@latest by npm install next-aws-lambda
  2. Then, as a more robust solution, bundle Functions in next-on-netlify and make sure next-aws-lambda is included during bundling

@ehmicky ehmicky removed their assignment Nov 13, 2020
@ehmicky
Copy link
Author

ehmicky commented Nov 17, 2020

Some PR at #48 for the first point.

@lindsaylevine
Copy link

lindsaylevine commented Nov 18, 2020

i just merged your PR and think we can close this issue. i just synced with finn and he's removing the next-aws-lambda dependency in a WIP PR: netlify/next-on-netlify#85

proposal:

  1. close this issue
  2. open another issue to remove the next-aws-lambda install once finn's PR is merged and published

let me know your thoughts! i defer to you @ehmicky

edit: merged finn's NoN PR, opened a followup PR in here :)

@ehmicky
Copy link
Author

ehmicky commented Nov 18, 2020

Yes, problem solved!

@ehmicky ehmicky closed this as completed Nov 18, 2020
@ehmicky ehmicky added the type: feature code contributing to the implementation of a feature and/or user facing functionality label Nov 18, 2020
ascorbic added a commit that referenced this issue Oct 4, 2021
* chore: don't force target

* fix: add warning

* fix: update tests
serhalp pushed a commit that referenced this issue Apr 5, 2024
feat: use NFT to trace handler dependencies
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: feature code contributing to the implementation of a feature and/or user facing functionality
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants