Module resolution `npm:` alias mapping assumes `node_modules` and eleventy config exist in same directory
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 1.4k
- Forks
- 46
- Avg merge
- 10m
- Merged PRs (30d)
- 2
Description
First of all: you rock! Love the projects, excellent work, very grateful ❤️
I described my issue in a comment in some more detail over in the eleventy-plugin-webc repo.
I have an issue loading the is-land plugin in an 11ty webc project. I have a large, complicated webapp codebase, where eleventy is but a small part of a larger system. The eleventy bits are located in a subdirectory of this project, ./public, while the package.json for this project exists one directory up, in the root of the project. Thus, node_modules exists one parent directory above where the eleventy project exists.
My particular problem boils down to two issues, I think, which are related:
- The
fsCachemodule seems (to me) unnecessarily restrictive re: requiring components to be subdirectories of the "working directory" npm:component loading aliasing assumesnpm:maps to./node_modules
Issue (1) effectively prevents setting webc component loading to any directory that is not an immediate subdirectory within the eleventy project. For a monorepo style setup, this seems like an unnecessarily restrictive constraint. As mentioned, since in my setup, node_modules is one level up above the eleventy project, that exception is troublesome. Could we consider dropping the code I linked to in (1)?
Issue (2) is related to the same problem: the npm: component loading alias assumes something about the location of the node_modules directory. There is a TODO here, tantalizingly hinting at perhaps the author foreseeing an issue similar to what I'm describing here. I was thinking one way to improve this would be to search up the file tree to find the npm project root first (by looking for the presence of a package.json file), and then joining that found project root with ./node_modules. I think that would solve this issue? What do you think?
I am happy to give a PR a go to try to fix this! I wanted first to check if my thinking is correct / is a PR worth it / would the project be responsive to the issue / provide guidance on how to go about improving the situation.
Thanks for any discussion and thank you once more for an amazing open source project!
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading src/fsCache.js and src/moduleResolution.js, especially the linked restrictions and the TODO around npm: aliasing. Reproduce the layout with the Eleventy project in ./public and package.json/node_modules in its parent directory. Done means component loading can resolve that setup without assuming both locations share a directory.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100