Skip to content
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

NextJS aggressively tries to load unnecessary dependencies #3672

Closed
1 task done
lacymorrow opened this issue Feb 4, 2018 · 3 comments
Closed
1 task done

NextJS aggressively tries to load unnecessary dependencies #3672

lacymorrow opened this issue Feb 4, 2018 · 3 comments

Comments

@lacymorrow
Copy link
Contributor

  • I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior

Using the npm-name module outputs true or false in a next project.

Current Behavior

Attempts to use npm-name result in the error:

This dependency was not found:  
* electron in ./node_modules/npm-name/node_modules/got/index.js  
To install it, you can run: npm install --save electron

Steps to Reproduce (for bugs)

In a Next.JS project:

import npmName from 'npm-name'
npmName('npm-name') // throws the error

Context

Trying to use the npm-name module results in Next throwing an error because electron is not installed. I don't want to introduce electron to the project obviously, and looking through the source of got, I'm not sure why it's being required.

Your Environment

Tech Version
next 4.2.3
node 9.2.0
OS macOS 10.12.6
browser chrome63

Corresponding ticket with npm-name: sindresorhus/npm-name#16
I believe this is a NextJS issue.

@lucleray
Copy link
Member

lucleray commented Feb 4, 2018

Next.js uses webpack that will analyze the code and bundle all the necessary packages.

So, in this case, I guess webpack will try to bundle electron since it's required in the the source of got.

Maybe you can fix that by adding some config to webpack to ignore electron package.

There is also this PR that could solve your problem : #3470

@lacymorrow
Copy link
Contributor Author

lacymorrow commented Feb 4, 2018

@lucleray Thanks for shedding some light on this!

I believe you're correct in what's happening, it's an unfortunate side-effect.

I chose to use a different library than got for the HTTP request, rather than modifying my webpack config

@timneutkens
Copy link
Member

got is for server side only. You need to use a universal fetching solution like isomorphic-fetch or isomorphic-unfetch

@lock lock bot locked as resolved and limited conversation to collaborators Feb 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants