Open Andarist opened 1 year ago
Hmm yeah that should probably be an InvalidSpecifier error instead of UnknownError. I'd also like to have more details in the error about how to enable package exports support.
Stumbled upon this when trying to build a library including node_modules.
parcel/core: Failed to resolve '#ansi-styles' from './node_modules/zx/node_modules/chalk/source/index.js'
/Volumes/Projects/Software/toolchain/node_modules/zx/node_modules/chalk/source/index.js:1:24
> 1 | import ansiStyles from '#ansi-styles';
> | ^^^^^^^^^^^^^^
2 | import supportsColor from '#supports-color';
3 | import { // eslint-disable-line import/order
@parcel/resolver-default: Cannot read properties of undefined (reading 'message')
Didn't realize packageExports: true
needs to be enabled manually!
🐛 bug report
Parcel crashes at runtime when resolving a simple
#is-development
specifier in a package withpackage.json#imports
without enablingpackageExports: true
:https://github.com/bvaughn/suspense/pull/34#issuecomment-1582969380
🎛 Configuration (.babelrc, package.json, cli command)
defaults
🤔 Expected Behavior
It should not crash
😯 Current Behavior
The
package.json#imports
support is not enabled by default, see this line: https://github.com/parcel-bundler/parcel/blob/76aa20fc2f752fae9c7347f071ea457b112a5dad/packages/utils/node-resolver-rs/src/lib.rs#L482So
UnknownError
is returned here: https://github.com/parcel-bundler/parcel/blob/76aa20fc2f752fae9c7347f071ea457b112a5dad/packages/utils/node-resolver-rs/src/lib.rs#L514The error isn't mapped to anything useful by this
handleError
call: https://github.com/parcel-bundler/parcel/blob/76aa20fc2f752fae9c7347f071ea457b112a5dad/packages/utils/node-resolver-core/src/Wrapper.js#L153So an empty
diagnostics
are returned here: https://github.com/parcel-bundler/parcel/blob/76aa20fc2f752fae9c7347f071ea457b112a5dad/packages/utils/node-resolver-core/src/Wrapper.js#L159That is being converted to
ThrowableDiagnostics
here: https://github.com/parcel-bundler/parcel/blob/76aa20fc2f752fae9c7347f071ea457b112a5dad/packages/core/core/src/requests/PathRequest.js#L369-L376but that expects non-empty array: https://github.com/parcel-bundler/parcel/blob/76aa20fc2f752fae9c7347f071ea457b112a5dad/packages/core/diagnostic/src/diagnostic.js#L202-L207
💁 Possible Solution
I think that a helpful diagnostic should be thrown here to suggest enabling
packageExports: true
. I also don't quite see a strong reason to not supportpackage.json#imports
by default so i think that enabling that is also an option but I also understand why you putpackage.json#exports
andpackage.json#imports
in a single bucket.💻 Code Sample
Can be reproduced on this commit with
pnpm run docs
🌍 Your Environment