# Aurelia-cli (RequireJS): move node\_modules to upper directory

**URL:** <https://discourse.aurelia.io/t/aurelia-cli-requirejs-move-node-modules-to-upper-directory/1288>\
**Category:** Help Requests\
**Created:** [June 6, 2018, 10:31am UTC](https://discourse.aurelia.io/t/aurelia-cli-requirejs-move-node-modules-to-upper-directory/1288 "2018-06-06T10:31:55Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![graycrow](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/graycrow/32/323_2.png) [@graycrow](https://discourse.aurelia.io/u/graycrow)\
**Post date:** [June 6, 2018, 10:31am UTC](https://discourse.aurelia.io/t/aurelia-cli-requirejs-move-node-modules-to-upper-directory/1288/1 "2018-06-06T10:31:55Z")

</div>

I have a few aurelia-cli based applications in the project and want to use Yarn Workspaces with them to avoid packages duplication, i.e. instead a node\_modules folder in every app just have one in the project root. This approach works for Webpack apps, but RequireJS based app can’t find dependencies without full path specified (like most of aurelia-\* dependencies, etc.).

Is it possible to specify a different default path for the node\_modules directory in the aurelia.json file?

---

<div class="post-metadata">

**Author:** ![graycrow](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/graycrow/32/323_2.png) [@graycrow](https://discourse.aurelia.io/u/graycrow)\
**Post date:** [June 6, 2018, 11:17am UTC](https://discourse.aurelia.io/t/aurelia-cli-requirejs-move-node-modules-to-upper-directory/1288/2 "2018-06-06T11:17:24Z")

</div>

So far, I’m using the following solution, which works, but adds a lot of extra lines to the aurelia.json:  
Instead of “short” dependency declaration, like `"aurelia-dependency-injection"` use a full form:

```
{
    "name": "aurelia-dependency-injection",
    "path": "../../node_modules/aurelia-dependency-injection/dist/amd",
    "main": "aurelia-dependency-injection"
}
```

---

<div class="post-metadata">

**Author:** ![huochunpeng](https://avatars.discourse-cdn.com/v4/letter/h/49beb7/32.png) [@huochunpeng](https://discourse.aurelia.io/u/huochunpeng)\
**Post date:** [June 6, 2018, 11:41pm UTC](https://discourse.aurelia.io/t/aurelia-cli-requirejs-move-node-modules-to-upper-directory/1288/3 "2018-06-06T23:41:00Z")

</div>

I had a look into this issue. The answer is cli doesn’t support it. If your filesystem supports symlink, you can try `ln -s ../node_modules node_modules`.

cli doesn’t resolve npm package path like nodejs does. It currently only looks into local node\_modules folder. But nodejs does much more. nodejs tries local node\_modules folder, then repeatedly tries all parent directories’ node\_modules folder, if it cannot resolve a package locally. Aftercall, nodejs also tries global paths defined by NODE\_PATH, and global nodejs packages (it looks like doesn’t try global npm installed packages).

**UPDATE: cli actually has some code to try parents’ node\_modules folder, but it doesn’t work like nodejs as cli doesn’t test whether `node_modules/packageName` exists. cli only tests whether `node_modules` exists, it unfortunately tries to use the blank local `node_modules` folder created by yarn workspaces.**

Your use case is the parent directory’s node\_modules folder.

[https://nodejs.org/api/modules.html#modules\_all\_together](https://nodejs.org/api/modules.html#modules_all_together)

Luckily nodejs provided an api to return a resolved path of a package `require.resolve('pacakageName');`

I will try to make a PR to fix cli’s package resolving code using that api, instead of hard coded `'node_modules'` search. This should not only improve compatibility, but also simplify cli code as it currently checks file existence manually.

---

<div class="post-metadata">

**Author:** ![huochunpeng](https://avatars.discourse-cdn.com/v4/letter/h/49beb7/32.png) [@huochunpeng](https://discourse.aurelia.io/u/huochunpeng)\
**Post date:** [June 6, 2018, 11:50pm UTC](https://discourse.aurelia.io/t/aurelia-cli-requirejs-move-node-modules-to-upper-directory/1288/4 "2018-06-06T23:50:36Z")

</div>

Forgot that current cli requires you to write lots of explicit config for dependencies.

Once you have any dependencies with `"path": "../node_modules/..."` in your aurelia.json, it bypasses my proposed future fix. The fix doesn’t make sense for current cli.

So I will only implement the fix in [auto-tracing version of cli](https://github.com/aurelia/cli/pull/862) which doesn’t require you to maintain explicit config.

---

<div class="post-metadata">

**Author:** ![huochunpeng](https://avatars.discourse-cdn.com/v4/letter/h/49beb7/32.png) [@huochunpeng](https://discourse.aurelia.io/u/huochunpeng)\
**Post date:** [June 7, 2018, 1:24am UTC](https://discourse.aurelia.io/t/aurelia-cli-requirejs-move-node-modules-to-upper-directory/1288/5 "2018-06-07T01:24:02Z")

</div>

Latest auto-tracing `huochunpeng/cli#at15` supports yarn workspaces.

Remember to remove all your explicit dependencies config following the test guide in the PR thread.

In addition, you need to adjust the prepend section to use `"../node_modules/..."` as they are all explicit paths.

---

<div class="post-metadata">

**Author:** ![graycrow](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/graycrow/32/323_2.png) [@graycrow](https://discourse.aurelia.io/u/graycrow)\
**Post date:** [June 11, 2018, 9:58am UTC](https://discourse.aurelia.io/t/aurelia-cli-requirejs-move-node-modules-to-upper-directory/1288/6 "2018-06-11T09:58:40Z")

</div>

Thank you, @huochunpeng! I will try `huochunpeng/cli#at15`, it looks really promising.

---

<div class="post-metadata">

**Author:** ![timfish](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/timfish/32/1566_2.png) [@timfish](https://discourse.aurelia.io/u/timfish)\
**Post date:** [June 12, 2018, 10:22pm UTC](https://discourse.aurelia.io/t/aurelia-cli-requirejs-move-node-modules-to-upper-directory/1288/7 "2018-06-12T22:22:34Z")

</div>

Can’t you use the yarn workspaces `nohoist` option? Sure, it means that you end up with multiple node\_modules directories but it’s how we’ve solved our monorepository woes while all the tooling plays catch up…
