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

Error using webpack: "ERROR in ./node_modules/got/index.js" #34

Closed
GabeDuarteM opened this issue Jul 17, 2017 · 11 comments
Closed

Error using webpack: "ERROR in ./node_modules/got/index.js" #34

GabeDuarteM opened this issue Jul 17, 2017 · 11 comments

Comments

@GabeDuarteM
Copy link

I don't know if it's just with me, but i'm trying to use this api with webpack, but when it builds it's giving me the error below:

ERROR in ./node_modules/got/index.js
Module not found: Error: Can't resolve 'electron' in 'D:\Users\gabri\Documents\Projetos\trakt.tv-test\node_modules\got'
 @ ./node_modules/got/index.js 45:20-39
 @ ./node_modules/trakt.tv/trakt.js
 @ ./index.js

I made a very simple repo just to demonstrate the error: https://github.com/GabrielDuarteM/trakt.tv-test
Just run yarn/npm install and yarn start/npm start and check the logs

Any ideas for what is causing it? It seems like its related to a dependent package you're using (got)

@GabeDuarteM
Copy link
Author

GabeDuarteM commented Jul 17, 2017

Apparently if you add the code below to your webpack.config file, the error disappears

externals: {
  electron: "electron"
}

I'm wondering, is that something you could do on your end to prevent those who uses this package to have to put this in webpack's config?

@janpio
Copy link
Contributor

janpio commented Jul 17, 2017

I had the exact same problem, but as I already knew it was a problem connected to got I posted there: sindresorhus/got#345

Turns out it is an issue with Webpack that doesn't like/understand/can handle the conditional require in got: webpack/webpack#5294

As you see got just got a commit that should fix this for all users as soon as it is released:
sindresorhus/got@e871099

(I have still some tabs open to figure out how to fix it for me locally, besides just installing electron as a devDep, so your code for webpack.config is welcome)

@GabeDuarteM
Copy link
Author

GabeDuarteM commented Jul 17, 2017

@janpio Nice, so when the next version of got gets published, this should be fixed, the only work required would be update the package itself. We should wait for it then...

As for how i managed to fix it locally, you can see at this file https://github.com/GabrielDuarteM/trakt-scrobbler/blob/master/webpack.config.ts#L51

This is a typescript file, but essencially the only thing i needed to do was to add the lines 51~53, and it started to work again... Didn't even needed to install electron as a dev-dependency.

Maybe it will start to pop another error from got, saying something like './packages' could not be resolved or something similar. To solve this i had to add the ".json" format at line 49, but this could be related to the way that i'm using typescript. Anyway, after that, Webpack was able to build without problems.

@janpio
Copy link
Contributor

janpio commented Jul 17, 2017

Nice. I will also wait for the got update and keep electron as devDependency for now, my webpack.config.ts is the default from @ionic/app-scripts (which uses webpack internally) so I don't really have that file yet. Easier this way.

Javascript is complicated sometimes ;)

@vankasteelj
Copy link
Owner

IMO I won't need to update anything as got probably won't go to 8.x on the next release, we can reopen if a got update is required here, but as I targeted 7.x.x, we should be good on trakt side

@janpio
Copy link
Contributor

janpio commented Mar 22, 2018

Just redownloaded my project and got the same error again.
got indeed did a 8.x release as the next one, so this fix unfortunately doesn't apply to this project :/
(And of your I now can't really figure out how I did fix it back in the day...)

@janpio
Copy link
Contributor

janpio commented Mar 22, 2018

I installed [email protected] into my project and it didn't explode, which I think is a good sign for you @vankasteelj

@vankasteelj
Copy link
Owner

Wait wait wait, I don't understand what's happening anymore. So is something my fault, something that I need to fix?

@janpio
Copy link
Contributor

janpio commented Mar 24, 2018

Nothing your fault, but you could upgrade the got dependency, then people won't get this error (under special circumstences) any more - because got 8.x includes a fix on their side. But of course it is a new major version, so no idea if something broke :/

@vankasteelj
Copy link
Owner

publishing the 7.x update with new API calls and got 8.x once npm servers are back online

@Mahesh-Webvistar
Copy link

is anyone found solution on this ???

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants