Questions related to 'npm install' and 'node_modules' - node-modules

When executing the 'npm install' command in a node project,
Is there a way to prevent certain directories (packages) in the node_modules directory from being updated?
In other words, is there a way to avoid touching the specific directory (package) itself in node_modules?
(I'm using a package that is not defined in the 'package.json file' content by manually putting it inside the 'node_modules directory'. I hope the package is not deleted when commanding 'npm install'.)

This situation is little complicated but you can try creating your private package.
the below test works, you can give it a try:
I have created a dummy package "foo" with:
"name": "#my-private-namespace/foo",
I created a folder:
$ npm init -y
...
$ npm install ../foo
...
$ ls node_modules/\#my-private-namespace/
foo
$ npm install n
...
$ ls node_modules/\#my-private-namespace/
foo

Related

Update yarn.lock after removing a workspace

Suppose I have a monorepo using the standard workspace structure:
monorepo
|- package.json
|- yarn.lock
|- packages
|- package_a
|- package_b
I want to completely get rid of package_a while also updating the yarn.lock accordingly.
The following doesn't update the lockfile:
$ rm -rf packages/package_a
$ yarn install
Running this in the root of the monorepo doesn't work either:
$ yarn remove -W package_a
error This module isn't specified in a package.json file.
This does work, but bumps all packages where the range allows which is not desired.
$ rm -rf packages/package_a
$ yarn upgrade
How can I accomplish this?
I may misunderstand your question... But it appears that you need to include each package in your package.json as mentioned with each workspace here: https://classic.yarnpkg.com/en/docs/workspaces/.
Needed in package.json:
{
"private": true,
"packages": ["package_a", "package_b"]
}
I'm guessing this is why you are getting the error error This module isn't specified in a package.json file. when attempting yarn remove -W package_a. When it is included in the package.json then just yarn remove package_a this will also update your yarn.lock automatically.
https://classic.yarnpkg.com/en/docs/cli/remove

aws "serverless invoke local" fails to run when node_modules are on a parent folder

I have a serverless aws app within a context of many other ones. All of the node_modules are shared in a parent folder, and it works fine with deploys and invoke functions, not with invoke local. This is my structure:
main/
- node_modules
- serverless
- app1
- app2
- serverless.yml
serverless.yml file settings:
package:
include:
- ../../node_modules/**
The problem is whenever I try to run sls invoke local I got a error messages due to package not found. So, the workaround is to npm install --save every package that is outside of my path.
If you have found a solution, not a workaround (like mine) please share :).
It was so obvious I wanted to delete my question, but I'll leave the answer here>
just go to the folder that contains your node_modules, you'll find a package.json there, and run npm install --save for the new packages you need.
cd ../../
npm install --save missing_packages
your serverless.yml include should consider it when running local with no issues.
Violá!

graphql-codegen not running with config file

In my package.json file I've got script entry that runs graphql-codegen but it complains that the --config argument is invalid:
$> yarn gen
yarn run v1.21.1
$ graphql-codegen --config codegen.yml
Error: Unknown argument: config
...
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Since I believe the default file name is codegen.yml anyway, I try to run it with out that argument and nothing gets generated:
$> yarn graphql-codegen
yarn run v1.21.1
$ /home/aaron/projects/my_app/node_modules/.bin/graphql-codegen
Done in 0.17s.
Any ideas?
for me this solved the issue
Yarn
yarn add -D #graphql-codegen/cli
npm
npm i -D #graphql-codegen/cli
installation guide doc
Ok, I'm not sure exactly what I did to fix this. I believe that I had also installed graphql-codegen globally and tried to uninstall it with sudo npm uninstall graphql-codegen which removed a bunch of packages but the executable still exists:
$>which graphql-codegen
/usr/bin/graphql-codegen
However I decided to run yarn graphql-codegen init on a whim to see if init was valid and because I couldn't remember if I hadn't tried that already. I got the set up questions like normal so I ctrl+C'ed and just ran yarn graphql-codegen and it worked! Then I ran yarn graphql-codegen --watch to test that it took options and that also worked.
If anyone gets this issue, I hope these tips help you.
Try it: rm -rf ./node_modules && npm install
rm http://manpages.ubuntu.com/manpages/trusty/man1/rm.1.html
remove files or directories
-f, --force ignore nonexistent files and arguments, never prompt
-r, -R, --recursive remove directories and their contents recursively
node_modules https://docs.npmjs.com/cli/v7/configuring-npm/folders
You can think of the node_modules folder like a cache
for the external modules that your project depends upon. When you npm
install them, they are downloaded from the web and copied into the
node_modules folder and nodejs is trained to look for them there when
you import them (without a specific path).
npm install https://docs.npmjs.com/cli/install/
This command installs a package and any packages that it depends on.
If the package has a package-lock, or an npm shrinkwrap file, or a
yarn lock file, the installation of dependencies will be driven by
that, respecting the following order of precedence:
npm-shrinkwrap.json
package-lock.json
yarn.lock
Might also be that you have apollo's graphql-codegen package installed, which also exposes a binary called graphql-codegen, which accepts args schema and output, but not config.
For me the solution was to install #graphql-codegen/cli.
graphql.config.yml
schema: http://localhost:8081/graphql
extensions:
codegen:
generates:
./schema.graphql:
- schema-ast
package.json
{
"codegen": "graphql codegen --config graphql.config.yml"
}
I've fixed the problem by using graphql-code-generator instead:
"scripts": {
"graphql:generate": "graphql-code-generator"
}

ESLint couldn't find the plugin "eslint-plugin-react"

I work in sublime-text 3 with the following project structure:
workdir
--root-project-dirictory
---- src
---- eslint.yml
--project.sublime-project
The problem is this: ESLint is looking for the eslint-plugin-react plugin in workdir and not in the root-project-dirictory.
As a result I get an error:
ESLint couldn't find the plugin "eslint-plugin-react".
(The package "eslint-plugin-react" was not found when loaded as a Node module from the directory "/.../workdir".)
...
The plugin "eslint-plugin-react" was referenced from the config file in "root-project-dirictory / .eslintrc.yml".
The problem is this: ESLint is looking for the eslint-plugin-react plugin in workdir and not in the root-project-dirictory.
If eslint-plugin-react is included in the root working directory then it should be installed in the root and you can then extend the sub config from the root.
Until now, I have not found a solution to this problem without changing the structure of the working directory.
As a solution, I use the following:
create an empty sublime-text project
add one by one folder to the project, such as "src", "app" ...
if files are needed in --root-project-dirictory, then add it, but I'm working on the application in separate sublime-text folders of the project
I faced the same issue and found the main reason and how to fix:
npx eslint . --fix
Oops! Something went wrong! :(
ESLint: 6.1.0.
ESLint couldn't find the plugin "eslint-plugin-import".
or this error
Error: Cannot find module 'eslint-config-airbnb'
To fix it run this:
$ rm -rf node_modules
$ npm install eslint --save
$ npm install eslint-config-airbnb-base --save
$ npm install eslint-plugin-markdown --save
$ npm install eslint-plugin-import --save
(install all other plugins)
$ npm i
$ npx eslint --version
(should be less than 7)
Now, it works:
npx eslint . --fix
Reason:
It seems if libs listed under dev reps, ESLint got updated automatically to 7.0 which is not ready yet. As you can see we had the same error before on version 6.
For me, the issue was that I was using eslint globally which does not have that plugin. I used the command npx eslint ... then it worked normally.
In my case I did find a .eslintrc.json file in the Project Parent folder. After deleting it everything went back to normal.

cp: cannot stat ‘build/docker/gotools/bin/protoc-gen-go’: No such file or directory

I try to build hyperledger fabric, and have installed the project as the guide in http://hyperledger-fabric.readthedocs.io/en/latest/Setup/Chaincode-setup/#option-1-vagrant-development-environment.
When I try to 'make peer', command is shown as:
vagrant#ubuntu-1404:/opt/gopath/src/github.com/hyperledger/fabric/devenv$
cp: cannot stat 'build/docker/gotools/bin/protoc-gen-go': No such file
or directory
I looked into the folder and didn't find the file protoc-gen-go. Does it indicate that I missed few steps when I was setting up the envrionment?
Step 1: Run
$go get -u github.com/golang/protobuf/protoc-gen-go
Download protoc-gen-go
Step 2: cp
$ cp $GOPATH/bin/protoc-gen-go build/docker/gotools/bin/
Then continue your make.
You can find the file protoc-gen-go in path: $GOPATH/bin, then copy this file to $GOPATH/src/github.com/hyperledger/fabric/build/docker/gotools/bin/.
If all things has done, you can run: make peer and it will work.
I had a same problem. Maybe your GOPATH and GOROOT variables are conflicted with your customized paths.
I solved the problem like this:
Delete /usr/lib/go
Delete /usr/local/go
Download protoc-gen-go ($go get -u github.com/golang/protobuf/protoc-gen-go)
protoc-gen-go binary is created at your go workspace
copy the protoc-gen-go binary to fabric/build/docker/gotools/bin/
BUILD AS make peer
I hope this would helpful to you
Can you try to:
cd /opt/gopath/src/github.com/hyperledger/fabric/
make peer
and see if it works? Looks like you are in the devenv subdir.
I had the same issue when Docker was returning permissions issues causing the build to fail.
Once that happens, the build process won't work successfully even after you fix the Docker issues.
Instead, once Docker is repaired, delete the gotools folder and run make again:
Makefile:245: recipe for target 'build/docker/gotools' failed
make: *** [build/docker/gotools] Error 126
user#:~/go/src/github.com/hyperledger/fabric$ rm -rf build/docker/gotools/
user#:~/go/src/github.com/hyperledger/fabric$ make all

Resources