X Tutup
The Wayback Machine - https://web.archive.org/web/20220519115657/https://github.com/preconstruct/preconstruct/issues/396
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

Module loading from its own package causes error #396

Open
with-heart opened this issue May 7, 2021 · 1 comment
Open

Module loading from its own package causes error #396

with-heart opened this issue May 7, 2021 · 1 comment

Comments

@with-heart
Copy link
Contributor

@with-heart with-heart commented May 7, 2021

If a module in a package refers to itself by its package name when importing, preconstruct build fails with the error the package is not specified in dependencies or peerDependencies. @Andarist felt that this should be reported.

See this PR review thread for more context (and @Andarist's comments): chakra-ui/chakra-ui#3956 (review)

Example of the error:

🎁 error @chakra-ui/utils "@chakra-ui/utils" is imported by "src/walk-object.ts" but the package is not specified in dependencies or peerDependencies

@mitchellhamilton
Copy link
Member

@mitchellhamilton mitchellhamilton commented Jun 9, 2021

Re @Andarist's comments:

Could you report this as a bug to preconstruct? I think this works now in node by default, according to the resolution algorithm: https://nodejs.org/api/modules.html#modules_all_together , It looks like LOAD_PACKAGE_SELF is allowing that explicitly.

I recall having some problems with that in the past and the previous version of the algorithm did not have this explicit step. However, I can't see why LOAD_NODE_MODULES would not allow this in the old algorithm so maybe this has always worked?

From testing, it seems like the LOAD_PACKAGE_SELF thing only happens when you have an exports field. The reason that it sort of works without an exports field is that when using Yarn workspaces currently is that it's essentially just "normal" resolution of a package in your node_modules since the package is symlinked into the root node_modules directory. That also means that without an exports field, if someone isn't using Yarn workspaces(or npm's workspaces, I suspect it would fine there too), like they only have a single package or they're using pnpm, the resolution wouldn't work in Node.

So I'm kinda leaning towards keeping it as is and not allowing it for now since it would kinda be deviating from Node module resolution to have it work always (which would mean that it wouldn't work with the require hook unless we did extra hackery).

Also, there is the question of "do you emit the import to the package name or have it resolve to the actual source?"

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

No branches or pull requests

2 participants
X Tutup