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

fix(ky-universal): server importing es bundle #121

Merged
merged 7 commits into from Aug 20, 2020
Merged

Conversation

privatenumber
Copy link
Contributor

Using @nuxt/http on Vercel via @nuxtjs/now-builder and was getting the following error on the server-side:

Screen Shot 2020-08-20 at 1 13 45 AM

I added a console.log(fetch); (as you can see above) and it was importing the ESM version (node-fetch/lib/index.es.js). I specified the specific CJS build explicitly.

@codecov-commenter
Copy link

codecov-commenter commented Aug 20, 2020

Codecov Report

Merging #121 into dev will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##              dev     #121   +/-   ##
=======================================
  Coverage   97.18%   97.18%           
=======================================
  Files           1        1           
  Lines          71       71           
  Branches       39       39           
=======================================
  Hits           69       69           
  Misses          2        2           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4ef88e4...cccff9d. Read the comment docs.

ky-universal/node.js Outdated Show resolved Hide resolved
@pi0
Copy link
Member

pi0 commented Aug 20, 2020

Hi @privatenumber and thanks for pull-request 👍

There is a strategy called interopDefault which we can do something like this:

const _interopDefault = (ex) => ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex

const fetch = _interopDefault(require('node-fetch'))

@privatenumber
Copy link
Contributor Author

Updated

Copy link
Member

@pi0 pi0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@privatenumber
Copy link
Contributor Author

privatenumber commented Aug 20, 2020

Actually, there's another bug. It expects the CJS version

Screen Shot 2020-08-20 at 1 50 59 PM

We'd have to either add a complicated named exports interop, or explicitly import the CJS version like it did before.


Sorry, noticed you approved it so had to comment quick before the merge

@pi0 pi0 changed the title fix: explicitly import CJS version of node-fetch fix: de-default node-fetch import Aug 20, 2020
@pi0
Copy link
Member

pi0 commented Aug 20, 2020

Actually, there's another bug. It expects the CJS version

@privatenumber Would you please elaborate more? What's the error with latest change?

@privatenumber
Copy link
Contributor Author

@pi0 Updated my comment

ky-universal/node.js Outdated Show resolved Hide resolved
@pi0 pi0 changed the title fix: de-default node-fetch import fix(ky-universal): server importing es bundle Aug 20, 2020
Co-authored-by: pooya parsa <pyapar@gmail.com>
@pi0 pi0 merged commit 029dea6 into nuxt:dev Aug 20, 2020
@pi0
Copy link
Member

pi0 commented Aug 20, 2020

https://github.com/nuxt/http/releases/tag/v0.5.11 released :D

@privatenumber
Copy link
Contributor Author

Thank you @pi0 🔥

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

Successfully merging this pull request may close these issues.

None yet

3 participants