emilkowalski / sonner

An opinionated toast component for React.
https://sonner.emilkowal.ski
MIT License
7.69k stars 237 forks source link

Build failure with Parcel #456

Closed adamhenson closed 1 week ago

adamhenson commented 1 week ago

Describe the feature / bug 📝:

In a minimal reproducible example here Parcel build fails with the following error

🚨 Build failed.

@parcel/core: Failed to resolve 'sonner' from './src/App.tsx'

  /Users/adam/Projects/parcel-sonner/src/App.tsx:1:32
  > 1 | import { Toaster, toast } from 'sonner';
  >   |                                ^^^^^^^^
    2 | 
    3 | export function App() {

@parcel/resolver-default: Cannot load file './index' from module 'sonner'

Steps to reproduce the bug 🔁:

  1. Setup a minimal example that imports from 'sonner' or clone git@github.com:adamhenson/parcel-sonner.git
  2. Run Parcel build with npx parcel src/index.html or with the cloned project npm run dev

Theory

My theory is that Parcel follows the NPM package.json docs strictly and perhaps requires a main entry.

If main is not set, it defaults to index.js in the package's root folder.

~ package.json | npm Docs

UPDATE: Seems like the issue could be due to conditional exports not supported by Parcel. I think this is good justification to add the main entry as a fallback for when conditional exports is not supported (like in the case of Parcel).

adamhenson commented 1 week ago

According to Node.js documentation, you should be able to rely exclusively on exports and with that said, this could be more of a Parcel bug:

For new packages targeting the currently supported versions of Node.js, the "exports" field is recommended. For packages supporting Node.js 10 and below, the "main" field is required. If both "exports" and "main" are defined, the "exports" field takes precedence over "main" in supported versions of Node.js.

Regardless, it would nice to support Parcel users by adding a main entry like so, as exports will take precedence anyways when supported.

"main": "./dist/index.js",
adamhenson commented 1 week ago

Seems like this could be due to conditional exports not supported in Parcel. Perhaps this adds more justification for a main entry in package.json (PR above).

adamhenson commented 1 week ago

🙏