Why doesn't Yarn install all executables in .bin folder? - npm

I've just started using the Yarn package manager and I downloaded a starter Ionic 2 project.
In this project, we have a lot of help from scripts that compile, minify, lint and bundle our code. All of this is provided by ionic-app-scripts, which has several dependencies which it uses to run commands.
The problem is when I use Yarn to install, the node_modules/.bin/ folder does not contain all the necessary executables, like tslint, which is a dependency of ionic-app-scripts, so it is not directly in my package.json.
The result is that when I use Yarn, ionic-app-scripts doesn't work because it expects that the .bin folder contains a tslint executable!
What can I do? Are the ionic-app-scripts's definitions a problem?
[note]: npm install works, but Yarn is much faster!

This is a known issue, and there's a pull request with more information.
In short, if you want to fix this now, you'll have to explicitly include the packages from which you need binaries in your dependencies.

I had this issue but a different solution.
The solution was from this ticket https://github.com/yarnpkg/yarn/issues/992#issuecomment-318996260
... my workaround is going to file manager, right click on /node_modules main folder, selecting properties, and check-uncheck "read-only". You can do it also using attrib in command line. Then you retry installation and it works.

Related

Do NPM workspaces make sense for server-side project where all the dependencies needs to be released using CI alongside the server code

NPM can be used for different things
front-end projects where the final artifacts often have all their dependencies included.
service side services where the node_modules directory is available to the runtime server code.
NPM currently hoists dependencies to the root node_modules folder in a workspace project. Even their new proposal https://github.com/npm/rfcs/blob/main/accepted/0042-isolated-mode.md still doesn't seem to allow for all dependencies to be installed just alongside the node_modules folder next to the package.json for that workspace folder. You either have to copy the root node_modules folder to a parent directory, which gets complicated releasing multiple services (since it's a shared resource), or you must merge the two which is also not trivial.
This becomes a problem when you want to build in a CI environment and then move the code and all dependencies somewhere else
Does anyone have thoughts on how they've solved/avoided/approached this problem?
I ended up going with Lerna, since it seems to handle this situation perfectly. Lerna basically treats every "sub-project" independently.
https://lerna.js.org/
I don't think npm workspaces fits this type of workflow, or it wasn't designed to be in the first place

Include package.json dependencies from another file

The Webpack/Vue ecosystem is a very fragile one, with minor updates to loaders regularly breaking the build. It's basically a dedicated job to curate a working Webpack config together with a list of the exact dependency versions that are needed to make it work.
This Webpack config can easily be kept in a repository and then copied to many different projects and imported in their local webpack.config.js because webpack.config.js is just Javascript.
I'd like to do the same thing with package.json, i.e. have the curated list of dependencies in a separate file and when running npm install have them added to any other dependencies a project might have.
Do npm or yarn or any other external tools offer such a functionality?
Are you specifically trying to use a js file? If so, I don't have an answer, but if json is enough, you can just make an node package that just has the dependencies you want in it. Someone that includes your package will then pull in all the dependencies listed in your package because npm pulls in the dependencies of a project's dependencies.
Also see https://stackoverflow.com/a/55483109/14144258

NPM module (handontable) not installing sub-dependency(numbro) as project dependencies

What I am trying to do:
So, I am installing a package which has a dependency numbro (another package). For my use case, I need to use that package and initialize it with some value. (set default currency)
However, I am not able to use that package in my code. As from inspecting package-json.lock, I can see that the package isn't there as direct project dependency but is present inside handontable's dependencies.
I thought, I can add numbro directly inside my package.json file to initialize some values but from what it seems, adding it direct and setting default value there doesn't solves the issue.
To check further, I created a dummy angular project with only handontable and handontable/angular to see, if I can reproduce the issue there. However, after npm install, I could use numbro package in the dummy project and the reason being it was present as direct project dependency in package-json.lock file.
The versions of numbro, handontable, handontable/angular and angular are all same in both projects but why is it that in one project I can use the the sub-dependency in my angular project but in another I cannot ?
Original Project:
Dummy Fiddle project:
(installed as direct project dependency)
So, I fixed it with some help from handsontable support team. I deleted node_modules folder and package-json.lock file both.
After which npm install did the trick.
I had tried deleting node_modules folder earlier but doing that alone doesn't resolved the issue.

Yeoman custom generator automatically install gulp + dependencies when creating new project

I'm brand new to Yeoman and even Gulp. I'm making websites that are very similar between them, so I'm trying to create a custom generator for Yeoman. I've managed to make template html files, and to copy over both files and folders when running the generator.
I made template package.json and gulpfile.js files with dependencies that all projects will be using, such as gulp, gulp-sass, gulp-autoprefixer, etc. My question now is: How do I make the generator automatically install npm and all dependencies when I run it in a new project? Or do I have to run npm install --save-dev *** for each dependency every time I create a new project?
Add the dependencies in the package.json files inside your generator.
For example https://github.com/yeoman/generator-node/blob/master/generators/gulp/index.js#L42 (there's other way to do this too. It depends on your needs)
Then you just call this.installDependencies().
You can also invoke commands:
generator.spawnCommandSync("bower", ["install"]);
generator.spawnCommandSync("npm", ["install"]);

Change entry point to npm dependency

I'm dependending on a library that publishes different module packages to npm (commonjs, ES2015, UMD bundles..) and specifies commonjs/index.js as the main point of the application.
However, I need my app to use the UMD bundle instead so I would need it to be bundles/index.umd.js instead.
I figured I could do this by looking into installed 'node_modules' and changing it directly in the package.json of downloaded library, but thats a very hacky thing to do.
Is there some other way of chanding the main file for the dependency?