-
Notifications
You must be signed in to change notification settings - Fork 357
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
Node package importer requires an entryPointDirectory in ESM #2178
Comments
I'm still not very excited about using the working directory instead of From nodejs/node#49440, it looks like we can get this information from |
This also updates the spec for `NodePackageImporter` to correctly document indicate that errors should be thrown during construction. See sass/dart-sass#2178
) This also updates the spec for `NodePackageImporter` to correctly document indicate that errors should be thrown during construction. See sass/dart-sass#2178
) This also updates the spec for `NodePackageImporter` to correctly document indicate that errors should be thrown during construction. See sass/dart-sass#2178
See sass/sass#3792
In addition to #2176, we are seeing that
require.main
is undefined in an ESM context. This means that@JS("require.main.filename")
is throwing the error `reading "filename" of undefined, which throws before the more helpful error can be thrown-Optional chaining is not supported by
@JS
syntax, but I was able to find a workaround in #2179.The second more significant issue is that, currently, because of this,
entryPointDirectory
is required in anESM
context.An equivalent to
require.main.filename
in ESM,import.meta.filename
is added in Node 21. However, even if we waited until that was available, because the mainsass.dart.js
file is CommonJS, we won't have access to that. From the Node docs-When the entry point is not a CommonJS module, require.main is undefined, and the main module is out of reach.
My proposal would be to use the current directory as a fallback when
require.main.filename
is not defined. It is not identical to the concept ofrequire.main.filename
, but does cover the most common case where the user is running the command from the directory that contains the package.I confirmed that
p.dirname(p.absolute('.'))
as the fallback for whenrequire.main.filename
is not defined allows aNodePackageImporter()
to be used without setting anentryPointDirectory
in ESM, but wanted to verify that's the correct path forward before committing.I think we had discussed the possibility of
require.main
not being available at one point, but had thought that the fixes made todart_cli_pkg
would address this as well.The text was updated successfully, but these errors were encountered: