yarn / npm install moving nested dependencies into unexpected folders - node.js

I am working on a repo with a big team and lots of contributors and have hit an unusual snag when trying to install a package I need. I can't link to any of the packages because they're private but here's the gist.
I want to install package1 which has package3 (v1.0) and package4 as nested dependencies (see below). package3 (v1.0) is a dependency of package 4. A different version of package3 (v2.0) is already a dependency in the repo.
package1
> package1 deps: package2
> package2 deps: package3 (v1.0), package4
After installing package1 I'd expect to see something in node_modules like...
node_modules
package1
node_modules
package2
node_modules
package3 v1
package4
package3 v2
But what I'm getting is more like...
node_modules
package1
node_modules
package2
node_modules
package3 v1
package4
package3 v2
So now package4 is actually trying to call methods on v2 of package3 instead of v1, because it's been moved up a few folders. Does anyone know what causes this behaviour and what to do to ensure the dependencies get installed in the "correct" order?

Related

Using yarn workspaces in project - workspace unable to resolve dependencies hoisted to project

I have a monorepo with the following file structure:
package.json
node_modules
yarn.lock
modules
- moduleA
- package.json
- node_modules
- moduleB
- package.json
- node_modules
In my top-level package.json I have:
"workspaces": ["modules/*"]
moduleB has no dependencies, at least not yet. When I ran yarn install in the root directory:
Almost all of moduleA's dependencies were installed in the root-level node_modules
VSCode is unable to resolve these dependencies inside of moduleA's source code
When I cd into moduleA and run a script, I get MODULE_NOT_FOUND errors for the hoisted dependencies.
Is there a way I can configure my project so that I can access hoisted dependencies from inside moduleA? I was unable to find anything about this in the Yarn dependencies. I have used nohoist as a workaround, but this is not optimal - I want to run my modules inside of their own directories and still be able to access shared dependencies.
Yarn version: 1.22.4

Install new version of child dependency without changing parent dependency in node

I have a node project my-app that depends on my-other-lib and my-test-lib, my-other-lib also has a dependency on my-test-lib.
This structure in node_modules looks like this:
my-app
├── my-other-lib#1.0.0
└── my-test-lib#1.0.0 (dev dependency)
└── my-other-lib#1.0.0
my-app uses my-other-lib to do some stuff on the production app, my-test-lib is a framework of sorts to help with testing. my-test-lib also makes use of my-other-lib.
I'm writing a test in my-app I want to add a bit of functionality to my-other-lib to help me in that test. I don't need to change any code in my-test-lib to get this working, however I can't figure out how to get this dependency to update without bumping the dependency version in my-test-lib and releasing a new version of it. It feels like I shouldn't have to do that.
If I release my-other-lib#1.1.0, then in my-app run npm install my-other-lib#1.1.0, I end up with this node_modules structure:
my-app
├── my-other-lib#1.1.0
└── my-test-lib#1.0.0 (dev dependency)
└── my-other-lib#1.0.0
One thing that seems odd to me is that my-test-lib specifies the dependency as my-other-lib: "^1.0.0" which implies that it should be fine with using 1.1.0, but still both packages are installed in node_modules.
Is there a way to have my-test-lib use my-other-lib#1.1.0 besides bumping the version in my-test-lib and releasing my-test-lib#1.1.0? And if not, what is the point of specifying the ^ in versions listed in package.json?
my-test-lib is also a npm repository, same as my-app, so you actual structure is the following.
my-app
├── my-other-lib#1.1.0
└── my-test-lib#1.0.0 (dev dependency)
└── my-other-lib#1.0.0
my-test-lib
└── my-other-lib#1.0.0
You need to have control over my-test-lib if you want to upgrade the packages.
let's say your folder structure looks like that:
workspace
├── my-app
└── my-test-lib
The process you should follow is the following (starting from workspace):
// go to your lib
cd my-test-lib
// upgrade my-other-lib
npm upgrade my-other-lib#^1.0.0
//increase your package.json version
// publish your new version
npm publish
// go back to your app
cd ../my-app
// upgrade my-test-lib
npm upgrade my-test-lib#^1.0.0
with this you should end up with the following structure:
my-app
├── my-other-lib#1.0.0
└── my-test-lib#x.x.x (dev dependency) (the new version you published)
└── my-other-lib#1.1.0
Cheers.

Missing directories and files on npm install

I'm trying to install this module with npm i --save https://github.com/yagop/node-telegram-bot-api.git.
The reason I avoid npm i --save node-telegram-bot-api is that I need some recently added methods (like sendContact).
When I install, it's added to my package.json as expected:
"node-telegram-bot-api": "git+https://github.com/yagop/node-telegram-bot-api.git",
But when I try to run app that is using this module it says:
Error: Cannot find module './src/telegram'
After poking around a little bit it turned out that there is missing src and some other directories. Here is tree output:
$ tree ./node_modules/node-telegram-bot-api
./node_modules/node-telegram-bot-api
├── CONTRIBUTING.md
├── index.js
├── LICENSE.md
├── node_modules
(second one is skipped)
├── package.json
├── README.hbs
└── README.md
Why? And how can I fix it?
I tried to npm cache clean and rm -rf ./node_modules/node-telegram-bot-api, reinstalling, nothing helps.
The problem is that the repository contains .npmignore file and the following files and directories are ignored during installation:
# lcov
coverage/
*.log
.package.json
# artifacts & source
README.hbs
output.md
output/
src/
test/
examples/
lib-doc/
# dotfiles
.travis.yml
.eslintrc
.eslintignore
.editorconfig
.babelrc
.gitignore
.git
So if you want to use the latest version from the repository, you need to download it and install it manually. Like that:
cd ./node_modules
git clone https://github.com/yagop/node-telegram-bot-api
cd ./node_modules/node-telegram-bot-api
npm install
Upd.: (imho) it is proper in this case to use a private registry for modules. For example sinopia.

npm: how to install the right package on naming conflicts?

I wanted to install this package: https://github.com/react-native-fellowship/react-native-navbar:
npm i react-native-navbar --save
But i've got another, outdated package from another source https://github.com/malkomalko/react-native-navbar:
$ npm list| grep navbar
├── react-native-navbar#1.5.0
│ ├── react-native-navbar#1.1.7 (git://github.com/malkomalko/react-native-navbar.git#fe3d9ed0c717e5304188e22f86ff63f0e029919f)
The first one, which i wanted to install, is a fork from the second, older one.
I already tried to update with "npm update" and i also tried to install a specific version with "npm i react-native-navbar#1.5.0", but it remains the same.
How to deal with such naming conflicts?
I found the root cause. One of my dependencies declared the "wrong" package as a dependency:
"dependencies": {
"react-native-navbar": "malkomalko/react-native-navbar",
"react-native-tabs": "malkomalko/react-native-tabs"
}

Ember CLI Crash on Rebuild after Clean install -- What am i doing wrong?

I have no idea what's wrong but when i change a file in my project, which triggers a rebuild, I get an EEXIST, file already exists error with a reference to a tmp file location.
To illustrate please see the following:
1) I start from a clean slate as instructed by Ember's release notes:
➜ code npm uninstall -g ember-cli
unbuild ember-cli#0.2.0-beta.1
➜ code npm cache clean
➜ code bower cache clean
bower deleted Cached package ember: /Users/userx/.cache/bower/packages/6c52274ebac940c836cec79e11a2d66a/1.10.0
bower deleted Cached package ember-cli-test-loader: /Users/userx/.cache/bower/packages/fe70ed35683979c3b9a86502abc892c8/0.1.3
bower deleted Cached package ember-load-initializers: /Users/userx/.cache/bower/packages/ace05fe526bc815d00157b3e7fdcccab/0.0.2
bower deleted Cached package ember-qunit: /Users/userx/.cache/bower/packages/6b2637f1e3c33e331968889fd7088678/0.2.8
bower deleted Cached package ember-qunit-notifications: /Users/userx/.cache/bower/packages/ebaf09c3e2e50cee4fa08625051f7d60/0.0.7
bower deleted Cached package ember-data: /Users/userx/.cache/bower/packages/b56c7ee7b1cb5f358555b733f3ec15c1/1.0.0-beta.15
bower deleted Cached package ember-cli-shims: /Users/userx/.cache/bower/packages/b2aa621bf259c52274bc62a524406e11/0.0.3
bower deleted Cached package loader.js: /Users/userx/.cache/bower/packages/b765bce6e48383520b38bc3732776d8e/1.0.1
bower deleted Cached package qunit-notifications: /Users/userx/.cache/bower/packages/cb84eb840aaebd3c38265d13fc3e2e70/0.0.6
bower deleted Cached package ember-resolver: /Users/userx/.cache/bower/packages/93ca6e97b9b9d8c72c8101fc00862583/0.1.12
bower deleted Cached package qunit: /Users/userx/.cache/bower/packages/db7350f12693d26675a7426499405707/1.17.1
bower deleted Cached package jquery: /Users/userx/.cache/bower/packages/fe2fe255e91d251051d543998aa8327a/1.11.2
bower deleted Cached package jquery: /Users/userx/.cache/bower/packages/fe2fe255e91d251051d543998aa8327a/2.1.3
2) Install Ember CLI 0.2.0-beta.1
➜ code npm install -g ember-cli#0.2.0-beta.1
/usr/local/bin/ember -> /usr/local/lib/node_modules/ember-cli/bin/ember
ember-cli#0.2.0-beta.1 /usr/local/lib/node_modules/ember-cli
├── abbrev#1.0.5
├── ember-cli-copy-dereference#1.0.0
├── js-string-escape#1.0.0
├── exit#0.1.2
├── debug#2.1.2 (ms#0.7.0)
├── temp#0.8.1 (rimraf#2.2.8)
├── symlink-or-copy#1.0.1 (copy-dereference#1.0.0)
├── http-proxy#1.8.1 (requires-port#0.0.0, eventemitter3#0.1.6)
├── promise-map-series#0.2.1 (rsvp#3.0.17)
├── yam#0.0.17 (fs-extra#0.8.1, findup#0.1.5, lodash#2.4.1)
├── broccoli-writer#0.1.1 (rsvp#3.0.17, quick-temp#0.1.2)
├── broccoli-sane-watcher#0.1.1 (broccoli-slow-trees#1.0.0, rsvp#3.0.17, sane#1.0.0-rc1)
├── broccoli-caching-writer#0.5.1 (rsvp#3.0.17, quick-temp#0.1.2, broccoli-kitchen-sink-helpers#0.2.6, core-object#0.0.2, rimraf#2.3.0)
├── broccoli-sourcemap-concat#0.4.3 (combined-stream#0.0.7, mkdirp#0.5.0, rsvp#3.0.17, broccoli-kitchen-sink-helpers#0.2.6, lodash-node#2.4.1, fast-sourcemap-concat#0.2.2, broccoli-caching-writer#0.5.3)
└── broccoli-es6modules#0.5.1 (walk-sync#0.1.3, mkdirp#0.5.0, rsvp#3.0.17, broccoli-kitchen-sink-helpers#0.2.6, broccoli-caching-writer#0.5.3, esperanto#0.6.17)
3) Prove to myself Ember/node/npm are all good
➜ code ember version
version: 0.2.0-beta.1
node: 0.12.0
npm: 2.1.8
4) Create a brand new Ember app
➜ code ember new an-app
version: 0.2.0-beta.1
installing
create .bowerrc
create .editorconfig
create .ember-cli
create .jshintrc
create .travis.yml
create Brocfile.js
create README.md
create app/app.js
create app/components/.gitkeep
create app/controllers/.gitkeep
create app/helpers/.gitkeep
create app/index.html
create app/models/.gitkeep
create app/router.js
create app/routes/.gitkeep
create app/styles/app.css
create app/templates/application.hbs
create app/templates/components/.gitkeep
create app/views/.gitkeep
create bower.json
create config/environment.js
create .gitignore
create package.json
create public/crossdomain.xml
create public/robots.txt
create testem.json
create tests/.jshintrc
create tests/helpers/resolver.js
create tests/helpers/start-app.js
create tests/index.html
create tests/test-helper.js
create tests/unit/.gitkeep
create vendor/.gitkeep
Installed packages for tooling via npm.
Installed browser packages via Bower.
Successfully initialized git.
5) Start up the app
➜ code cd an-app
➜ an-app git:(master) ember server
version: 0.2.0-beta.1
Livereload server on port 35729
Serving on http://0.0.0.0:4200/
Build successful - 3682ms.
Slowest Trees | Total
-------------------------------+----------------
Concat: Vendor | 3046ms
6) Save an unmodified router.js which will trigger a rebuild. This is where things crash.
file changed router.js
EEXIST, file already exists '/Users/userx/code/an-app/tmp/caching-writer-dest-dir_4SJKQT.tmp'
Error: EEXIST, file already exists '/Users/userx/code/an-app/tmp/caching-writer-dest-dir_4SJKQT.tmp'
at Error (native)
at Object.fs.symlinkSync (fs.js:852:18)
at symlink (/Users/userx/code/an-app/node_modules/ember-cli/node_modules/symlink-or-copy/index.js:82:14)
at Function.symlinkOrCopySync (/Users/userx/code/an-app/node_modules/ember-cli/node_modules/symlink-or-copy/index.js:58:5)
at /Users/userx/code/an-app/node_modules/ember-cli/node_modules/broccoli-sourcemap-concat/node_modules/broccoli-caching-writer/index.js:103:21
at lib$rsvp$$internal$$tryCatch (/Users/userx/code/an-app/node_modules/ember-cli/node_modules/promise-map-series/node_modules/rsvp/dist/rsvp.js:489:16)
at lib$rsvp$$internal$$invokeCallback (/Users/userx/code/an-app/node_modules/ember-cli/node_modules/promise-map-series/node_modules/rsvp/dist/rsvp.js:501:17)
at lib$rsvp$$internal$$publish (/Users/userx/code/an-app/node_modules/ember-cli/node_modules/promise-map-series/node_modules/rsvp/dist/rsvp.js:472:11)
at lib$rsvp$asap$$flush (/Users/userx/code/an-app/node_modules/ember-cli/node_modules/promise-map-series/node_modules/rsvp/dist/rsvp.js:1290:9)
at process._tickCallback (node.js:355:11)
I really have no idea how / where to start debugging this. I have tried the previous version of node, io.js and removing/reinstalling watcher. All have failed.
Thank you for your time.
The Ember CLI community found a fix for this issue overnight. You can view the discussion at the following link: https://github.com/ember-cli/ember-cli/issues/3413
The long and short of it: modify your package.json file to include "broccoli-sass": "^0.4.0" under devDependencies, and "rimraf":"2.2.8" under your listed dependencies.
I can confirm that if you make these changes, then delete /node_modules, /bower_components, and /tmp, then perform npm install and bower install, then run ember server, your project will auto-update correctly when a file changes.
Just don't ask me why.

Resources