unfetch icon indicating copy to clipboard operation
unfetch copied to clipboard

fix: invalid path for export in package.json (v 5.0.0)

Open cristianoliveira opened this issue 2 years ago • 16 comments

First of all, thanks for this library! We have been using it for quite a long time, and it works like a charm.

Description

It seems that there are invalid values exported in the package.json https://github.com/developit/unfetch/blob/main/package.json#L18

It causes issue while using unfetch as a module, for instance, we use webpack and once upgraded to 5.0.0 it started to break the build with the given (not so clear, to say the least) error:

ERROR in ./src/index.js 1:0-30
Module not found: Error: Can't resolve 'unfetch' in '/Users/user/dev/unfetch-issue-demo/src'
resolve 'unfetch' in '/Users/user/dev/unfetch-issue-demo/src'
  Parsed request is a module
  using description file: /Users/user/dev/unfetch-issue-demo/package.json (relative path: ./src)
    Field 'browser' doesn't contain a valid alias configuration
    resolve as module
      /Users/user/dev/unfetch-issue-demo/src/node_modules doesn't exist or is not a directory
      looking for modules in /Users/user/dev/unfetch-issue-demo/node_modules
        single file module
          using description file: /Users/user/dev/unfetch-issue-demo/package.json (relative path: ./node_modules/unfetch)
            no extension
              Field 'browser' doesn't contain a valid alias configuration
              /Users/user/dev/unfetch-issue-demo/node_modules/unfetch is not a file
            .tsx
              Field 'browser' doesn't contain a valid alias configuration
              /Users/user/dev/unfetch-issue-demo/node_modules/unfetch.tsx doesn't exist
            .ts
              Field 'browser' doesn't contain a valid alias configuration
              /Users/user/dev/unfetch-issue-demo/node_modules/unfetch.ts doesn't exist
            .js
              Field 'browser' doesn't contain a valid alias configuration
              /Users/user/dev/unfetch-issue-demo/node_modules/unfetch.js doesn't exist
            .jsx
              Field 'browser' doesn't contain a valid alias configuration
              /Users/user/dev/unfetch-issue-demo/node_modules/unfetch.jsx doesn't exist
        existing directory /Users/user/dev/unfetch-issue-demo/node_modules/unfetch
...

Demo

Here you can see an example of this issue: https://github.com/cristianoliveira/unfetch-issue-demo

Solution

After pointing to src/index.mjs it started to compile again and it is working as expected. 😄

Let me know if this is the right solution.

Relates to

https://github.com/developit/unfetch/issues/163 https://github.com/developit/unfetch/issues/162

cristianoliveira avatar Feb 10 '23 16:02 cristianoliveira

For those who use webpack and want a quick fix, while this isn't correctly addressed, you can create an alias and point to the correct file:

In the webpack.config.js include:

  resolve: {
    alias: {
      'unfetch': path.resolve(__dirname, 'node_modules/unfetch/dist/unfetch.mjs'),
    },
  },

cristianoliveira avatar Feb 10 '23 16:02 cristianoliveira

Looks correct to me!

rschristian avatar Feb 15 '23 19:02 rschristian

@rschristian @developit pinging in case you have forgotten to approve

ayZagen avatar Mar 27 '23 18:03 ayZagen

Sorry, not a maintainer, my approval does nothing. Just a drive-by suggestion as I ran into this and was seeing if anyone had submitted a fix yet.

rschristian avatar Mar 28 '23 02:03 rschristian

For those who use webpack and want a quick fix, while this isn't correctly addressed, you can create an alias and point to the correct file:

In the webpack.config.js include:

  resolve: {
    alias: {
      'unfetch': path.resolve(__dirname, 'node_modules/unfetch/dist/unfetch.mjs'),
    },
  },

Workes fine. Thanks

denizsult avatar Jun 01 '23 08:06 denizsult

Can this be merged? I really need this change since in cannot start storybook in my project, Thanks for fixing this! 🥳

Skopea avatar Sep 09 '23 20:09 Skopea

@rschristian , Kindly approve & merge it

alinasir85 avatar Oct 23 '23 19:10 alinasir85

@rschristian , Kindly approve & merge it

https://github.com/developit/unfetch/pull/164#issuecomment-1486112998

rschristian avatar Oct 23 '23 19:10 rschristian

@rschristian , Kindly approve & merge it

#164 (comment)

But its showing that your review is pending..

Screenshot 2023-10-24 at 12 47 32 AM

alinasir85 avatar Oct 23 '23 19:10 alinasir85

Doesn't matter -- GitHub's UI is a bit weird there for sure, but the approval of non-maintainers does nothing. You'd see a "collaborator" badge (I think) next to my name if I was able to approve and merge.

rschristian avatar Oct 23 '23 19:10 rschristian

@developit ?

alinasir85 avatar Oct 23 '23 19:10 alinasir85

This would be really nice to have merged since it currently is unusable in vite without a manual override.

For anyone else using vite, adding a resolve alias solved this for now:

defineConfig({
  resolve: {
    alias: {
      unfetch: path.resolve(__dirname, "node_modules/unfetch/dist/unfetch.mjs"),
    }
  }
})

katerberg avatar Oct 24 '23 22:10 katerberg

This would be really nice to have merged since it currently is unusable in vite without a manual override.

=> Failed to build the preview ReferenceError: path is not defined

And if I'm importing

import path from 'path';

I'm still getting Error: Failed to resolve entry for package "unfetch". The package may have incorrect main/module/exports specified in its package.json.

tdacu avatar Nov 16 '23 09:11 tdacu

Can someone merge this, please?

tim-kilian avatar Mar 28 '24 14:03 tim-kilian