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

Add default to exports in package.json #55

Closed
LeoLetourneur opened this issue Sep 13, 2024 · 1 comment
Closed

Add default to exports in package.json #55

LeoLetourneur opened this issue Sep 13, 2024 · 1 comment

Comments

@LeoLetourneur
Copy link

Hi,

as stated here :

I think the build configuration is missing something in the export.
When I build and then launch the app, it's working find.
But when I launch my unit test with Jest, like that

import PostalMime from 'postal-mime';

jest.mock('postal-mime', () => ({
  parse: jest.fn(),
}));

it is throwing the below error :

Cannot find module 'postal-mime' from 'my/file.test.ts'

      4 |
    > 5 | jest.mock('postal-mime', () => ({
        |      ^
      6 |   parse: jest.fn(),
      7 | }));
      8 |

      at Resolver._throwModNotFoundError (node_modules/jest-resolve/build/resolver...)

if I put the default node in your lib package.json exports like so

"exports": {
        "import": "./src/postal-mime.js",
        "default": "./src/postal-mime.js",
        "types": "./postal-mime.d.ts"
},

or completly remove the exports node
its working.

I don't see so many exports in other libraries' package.json,
so it might be working only with main & types (without exports).

Am I missing something ?

An other question, why do we need to use import PostalMime from './node_modules/postal-mime/src/postal-mime.js'; for browser instead of import PostalMime from 'postal-mime'; (written in readme) ? I'm using the second one, and it's working.

Thanks a lot for your lib !
Léo

@andris9
Copy link
Contributor

andris9 commented Sep 14, 2024

PostalMime is an ESM module and, as such, does not need to be bundled or built at all. In order for the browser to know where the PostalMime's ESM module file actually is, you would need to use the full file path for the import. As you probably use some kind of bundling, then the bundler sets the location instead.

@andris9 andris9 closed this as completed Sep 14, 2024
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

2 participants