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

Build failure with Parcel #456

Closed
adamhenson opened this issue Jun 22, 2024 · 3 comments · Fixed by #457
Closed

Build failure with Parcel #456

adamhenson opened this issue Jun 22, 2024 · 3 comments · Fixed by #457

Comments

@adamhenson
Copy link
Contributor

adamhenson commented Jun 22, 2024

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

@adamhenson
Copy link
Contributor Author

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
Copy link
Contributor Author

adamhenson commented Jun 22, 2024

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
Copy link
Contributor Author

🙏

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

Successfully merging a pull request may close this issue.

1 participant