emilkowalski/sonner

Build failure with Parcel

adamhenson opened this issue ยท 3 comments

Describe the feature / bug ๐Ÿ“:

  • Node Version: 20.15.0
  • NPM Version: 10.7.0
  • Parcel Version: 2.12.0
  • Sonner Version: 1.5.0

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).

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",

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).

๐Ÿ™