0

If I have a folder structure like this

root
|
|-src
| |-components
|
|-otherSrc
| |-components
|   |-sub_components
| |-node_modules
|
|-node_modules

Is it possible to load libraries referenced in root/src/components/.js from root/node_modules and for root/othersrc/components/.js from root/othersrc/node_modules (or root/othersrc/components/sub_components/*.js from root/othersrc/node_modules)

1 Answer 1

2

No, node_modules will be scanned only relative to the current directory going up to the root, so your deeply nested directories won't be searched for as candidates for resolving packages.

You can either install all the dependencies somewhere in the ancestry (e.g. /node_modules) or configure resolve.modules and use absolute imports or you'll have to specify relative paths in the packages in node_modules that will only work on your computer.

These approaches leave you at a disadvantage because it's hard to move your sources between machines, ensure that the correct dependencies are resolved and that they can be kept up-to-date. If you really want modularize your application into "components" that have their own dependencies and can be independently redistributed and maintained from the rest of your sources, then you might want to look into the monorepository pattern.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.