Skip to content
This repository has been archived by the owner on Sep 16, 2023. It is now read-only.

No "main" provided in package.json #693

Closed
zzolo opened this issue Dec 23, 2018 · 6 comments
Closed

No "main" provided in package.json #693

zzolo opened this issue Dec 23, 2018 · 6 comments

Comments

@zzolo
Copy link

zzolo commented Dec 23, 2018

I am trying to require a module that has a "module" field in package.json, which is an ESM version, but has no "main" field.

The package I am trying to require is layercake.

My use is a bit complex, since I am building things within Gulp, within Svelte, and layercake has it's own Svelte components, but my esm include looks like this:

require = require('esm')(module);

When I run things, I get the following error: Error: Cannot find module 'layercake'

If I manually add a "main" field to the package.json of layercake and set it to the same file as the "module" field, things work fine.

I assume there is some assumption about "main" that I don't know about and it would be great to understand that. Or, maybe it's a bug, but I doubt that.

Thanks for the help and great library; sorry if this is a duplicate.

@jdalton
Copy link
Member

jdalton commented Dec 23, 2018

Hi @zzolo!

Thank you for the kind words! You can use the "mainFields" options:

"mainFields": ["main", "module"]

@jdalton jdalton closed this as completed Dec 23, 2018
@zzolo
Copy link
Author

zzolo commented Dec 23, 2018

Thanks for the speedy response.

If I do this, I still get the same error:

require = require('esm')(module, {
  mainFields: ['main', 'module']
});

@jdalton
Copy link
Member

jdalton commented Dec 23, 2018

Okay!

@zzolo would you please make a simple repro repo so I can check it out?

@zzolo
Copy link
Author

zzolo commented Dec 23, 2018

Was just working on that. Here you go:
https://github.com/zzolo/esm-no-main-test

@jdalton
Copy link
Member

jdalton commented Dec 24, 2018

Patched 1657a1b.

@zzolo
Copy link
Author

zzolo commented Dec 25, 2018

Awesome, thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

2 participants