Node dependencies error: ENOTEMPTY: directory not empty - node.js

I have a problem with local dependencies. I don't understand how to fix it.
You can see all steps to reproduce my error.
Someone have an idea ? Thank a lot
Steps to reproduce
$ npm i --prefix module-a
OK
$ npm i --prefix module-b
OK
$ npm i --prefix module-c
npm WARN tar ENOENT: no such file or directory, open 'module-c/node_modules/.staging/...'
npm WARN tar ENOENT: no such file or directory, open 'module-c/node_modules/.staging/...'
npm WARN tar ENOENT: no such file or directory, open 'module-c/node_modules/.staging/...'
...
npm ERR! code ENOTEMPTY
npm ERR! syscall rmdir
npm ERR! path module-c/node_modules/.staging/core-js-pure-7ef16f00
npm ERR! errno -39
npm ERR! ENOTEMPTY: directory not empty, rmdir 'module-c/node_modules/.staging/core-js-pure-7ef16f00'
Env
$ npm -v
6.14.6
$ node -v
v10.22.1
Files
module-a/package.json
{
"name": "aaa",
"main": "index.js"
}
module-b/package.json
{
"name": "bbb",
"main": "index.js",
"dependencies": {
"aaa": "file:../module-a"
}
}
module-c/package.json
{
"name": "ccc",
"main": "index.js",
"dependencies": {
"aaa": "file:../module-a",
"bbb": "file:../module-b"
}
}
For you information, I have try with npm link. This solution work on my dev env but it doesn't work on other environnements because build and run are executed on 2 differents servers (so run server doesn't have bbb package in global packages and I have the error Cannot find package bbb).
module-c/package.json
{
"name": "ccc",
"main": "index.js",
"script": {
"postinstall": "cd ../module-b && npm link && cd - && npm link bbb"
},
"dependencies": {
"aaa": "file:../module-a"
}
}

Related

Getting error on npm install `npm WARN tar zlib: incorrect data check`

What is happening?
When I run npm install from my project directory, I am presented with this message:
npm WARN tar zlib: incorrect data check
npm WARN tarball cached data for acorn#https://registry.npmjs.org/acorn/-/acorn-7.4.1.tgz (sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A==) seems to be corrupted. Refreshing cache.
npm WARN tar zlib: incorrect data check
npm WARN tarball cached data for regexpp#https://registry.npmjs.org/regexpp/-/regexpp-2.0.1.tgz (sha512-lv0M6+TkDVniA3aD1Eg0DVpfU/booSu7Eev3TDO/mZKHBfVjgCGTV4t4buppESEYDtkArYFOxTJWv6S5C+iaNw==) seems to be corrupted. Refreshing cache.
npm WARN deprecated flatten#1.0.3: flatten is deprecated in favor of utility frameworks such as lodash.
npm WARN tarball tarball data for regexpp#https://registry.npmjs.org/regexpp/-/regexpp-2.0.1.tgz (sha512-lv0M6+TkDVniA3aD1Eg0DVpfU/booSu7Eev3TDO/mZKHBfVjgCGTV4t4buppESEYDtkArYFOxTJWv6S5C+iaNw==) seems to be corrupted. Trying again.
npm WARN tarball tarball data for acorn#https://registry.npmjs.org/acorn/-/acorn-7.4.1.tgz (sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A==) seems to be corrupted. Trying again.
npm WARN tar TAR_ENTRY_INVALID checksum failure
npm WARN tar zlib: incorrect data check
npm WARN tarball tarball data for #angular/compiler#https://registry.npmjs.org/#angular/compiler/-/compiler-8.2.14.tgz (sha512-ABZO4E7eeFA1QyJ2trDezxeQM5ZFa1dXw1Mpl/+1vuXDKNjJgNyWYwKp/NwRkLmrsuV0yv4UDCDe4kJOGbPKnw==) seems to be corrupted. Trying again.
npm WARN tarball tarball data for #angular/compiler#https://registry.npmjs.org/#angular/compiler/-/compiler-8.2.14.tgz (sha512-ABZO4E7eeFA1QyJ2trDezxeQM5ZFa1dXw1Mpl/+1vuXDKNjJgNyWYwKp/NwRkLmrsuV0yv4UDCDe4kJOGbPKnw==) seems to be corrupted. Trying again.
npm ERR! code ENOENT
npm ERR! syscall stat
npm ERR! path /Users/USERNAME/.npm/_cacache/content-v2/sha512/00/16/4ee04ede785035432276b6b0decf17903396456b5757c3532997ffb5bee5c328d8c980dc966302a9fcdc1190b9abb2e574cafe140c20dee2424e19b3ca9f
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, stat '/Users/USERNAME/.npm/_cacache/content-v2/sha512/00/16/4ee04ede785035432276b6b0decf17903396456b5757c3532997ffb5bee5c328d8c980dc966302a9fcdc1190b9abb2e574cafe140c20dee2424e19b3ca9f'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/USERNAME/.npm/_logs/2023-01-31T17_52_09_696Z-debug-0.log
Here is my package.json:
{
"name": "my-api",
"version": "2.0.0",
"description": "",
"scripts": {
"dev": "docker-compose up -d; aws-vault exec nonprod -- sam local start-api -t sam-update.yml --docker-network sam-local --env-vars env.json",
"build": "bash -c './bin/build.sh'",
"deploy": "bash -c './bin/deploy.sh $npm_package_name $0 $1'",
"invoke": "sam local invoke -t sam-update.yml --docker-network sam-local --env-vars env.json",
"lint": "prettier-standard --format --lint './src/**/*.{js,jsx,ts,tsx,css,scss}'",
"lint-ci": "prettier-standard --lint './src/**/*.{js,jsx,ts,tsx,css,scss}'",
"meta": "bash -c './bin/meta.sh $npm_package_name $0 $1'",
"package": "bash -c './bin/package.sh $npm_package_name $0 $1'",
"postinstall": "pip install -r requirements-dev.txt && husky install",
"setup": "bash -c './bin/setup.sh $npm_package_name $0 $1'",
"test": "NODE_ENV=test jest -u",
"test:coverage": "mkdir -p ./src/coverage ; NODE_ENV=test jest --coverage | tee ./src/coverage/coverage.txt",
"test-ci": "NODE_ENV=test jest --silent",
"update": "bash -c './bin/update.sh $npm_package_name $0 $1'"
},
"license": "CC BY-SA",
"keywords": [],
"devDependencies": {
"husky": "^5.2.0",
"jest": "^29.3.1",
"prettier-standard": "^16.4.1"
},
"overrides": {
"find-parent-dir": "0.3.1"
},
"eslintConfig": {
"env": {
"jest": true,
"node": true,
"es6": true
},
"parserOptions": {
"sourceType": "module",
"ecmaVersion": 2020
},
"ignorePatterns": [
"**/node_modules/**",
"**/*.spec.js"
]
},
"jest": {
"coverageReporters": [
"json-summary",
"text"
],
"collectCoverageFrom": [
"<rootDir>/**/*.js"
],
"setupFiles": [
"<rootDir>/../.jest/setEnvVars.js"
],
"modulePaths": [
"<rootDir>/layers/AuthorizerLayer/nodejs/node_modules",
"<rootDir>/layers/PlagiarismLayer/nodejs/node_modules",
"<rootDir>/layers/WebsocketLayer/nodejs/node_modules"
],
"moduleNameMapper": {
"/opt/(\\w*)": "<rootDir>/../src/layers/$1/$1.js",
"aws-sdk": "<rootDir>/../__mocks__/aws-sdk",
"aws-xray-sdk": "<rootDir>/../__mocks__/aws-xray-sdk"
},
"rootDir": "./src",
"testEnvironment": "node"
},
"prettier": {
"semi": true,
"trailingComma": "es5",
"arrowParens": "avoid",
"singleQuote": true
}
}
What I have tried to fix:
The first thing I did was set a temporary cache location with npm install --cache=/tmp/cache/ which didn't solve the issue. After that I just started throwing solutions hoping something would work without understanding fully what was happening. Should also note, first thing I did was delete all node_modules, and package-lock.json files within the repo.
I ran npm cache clean
Deleted the repo from my local machine and recloned
Uninstalled node version (via nvm) and reinstalled
Completely uninstalled node and nvm, deleted the .node, .npm and all other *node* folders on my mac, then restarted and reinstalled nvm and node
After all of that still getting the same error messages. If create a new directory on my machine and init a package.json and then run npm install --save-dev husky prettier-standard jest it all installs just fine. Leaving me to believe it is an issue with the repo, however, no one else on my team is experiencing this issue with the same repo on their machine. So not sure what is going on or how to fix it.

Can't install any npm packages

I can't install any npm packages. I type in npm install lodash and I get:
npm WARN webdev#1.0.0 No description
npm WARN webdev#1.0.0 No repository field.
npm ERR! path C:\Users\Blake\Desktop\webdev\node_modules\lodash
npm ERR! code ENOENT
npm ERR! errno -4058
npm ERR! syscall rename
npm ERR! enoent ENOENT: no such file or directory, rename 'C:\Users\Blake\Desktop\webdev\node_modules\lodash' -> 'C:\Users\Blake\Desktop\webdev\node_modules\.lodash.DELETE'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Blake\AppData\Roaming\npm-cache\_logs\2018-03-15T21_28_45_978Z-debug.log
My package.json file looks like:
{
"name": "webdev",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
I'm not sure what is wrong. I've tried uninstalling and reinstalling node.js. My npm version is 5.6.0. This happens with every package I've tried to install. Please help, I've been trying to fix this for hours to no avail.
EDIT: I fixed it! The absolute nightmare of a program, MalwareBytes Antimalware was blocking it. I quit out of MalwareBytes and now it is working. Not the first time that program has messed up my coding.
Delete package.json and package-lock.json file, use npm init and try again.
Probably directory node_modules doesnt exist in your project working directory
I would make sure you have npm installed locally in your working directory by running npm init. I would also try re-installing npm.
EDIT:
Remove MalwareBytes Anti-Malware.

Use dependencies from a private GitLab with NPM

I'm trying to install NPM dependencies from a private GitLab instence.
So, I have my repo with basic files
And I added this dependencie in the package.json on my project
"node-demo-package": "https://oauth2:<ACCESS TOKEN>#gitlab.fullurl.git"
But, when I run npm install, I receive this error message:
npm ERR! code ENOPACKAGEJSON
npm ERR! package.json Non-registry package missing package.json: node-demo-package#https://oauth2:<ACCESS TOKEN>#gitlab.fullurl.git.
npm ERR! package.json npm can't find a package.json file in your current directory.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/arnaud.delante/.npm/_logs/2018-01-24T15_05_49_456Z-debug.log
Which I don't understand as there is a package.json as showed in the screenshot.
Here it is
{
"name": "demo-package",
"version": "1.0.0",
"description": "Test pasckage",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git#gitlab.fullurl.git"
},
"author": "Arnaud Delante",
"license": "MIT"
}
I already tried switching https by git+https but I get another error
npm ERR! Error while executing:
npm ERR! /usr/local/bin/git ls-remote -h -t https://oauth2:<ACCES TOKEN>#gitlab.fullrul.git
npm ERR!
npm ERR! remote: You are not allowed to download code from this project.
npm ERR! fatal: unable to access 'https://oauth2:<ACCES TOKEN>#gitlab.fullrul.git': The requested URL returned error: 403
npm ERR!
npm ERR! exited with error code: 128
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/arnaud.delante/.npm/_logs/2018-01-24T17_19_16_677Z-debug.log
Which is weird because the token is correct.
Would you have any idea?
In package.json try to replace https:// by git+https://
doc : https://docs.npmjs.com/files/package.json#git-urls-as-dependencies

Publish npm, and after installation on other PC have error

and then install it on other pc to check. Bu after install package and it depencies i have error when try to start it
pm ERR! Linux 4.10.0-38-generic
npm ERR! argv "/home/pavlo/.nvm/versions/node/v6.11.4/bin/node" "/home/pavlo/.nvm/versions/node/v6.11.4/bin/npm" "start" "storjboard"
npm ERR! node v6.11.4
npm ERR! npm v3.10.10
npm ERR! path /home/pavlo/Desktop/test/package.json
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall open
npm ERR! enoent ENOENT: no such file or directory, open '/home/pavlo/Desktop/test/package.json'
npm ERR! enoent ENOENT: no such file or directory, open '/home/pavlo/Desktop/test/package.json'
npm ERR! enoent This is most likely not a problem with npm itself
npm ERR! enoent and is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! Please include the following file with any support request:
npm ERR! /home/pavlo/Desktop/test/npm-debug.log
Problem it that i have to clone package.json from git , how i can publish correctly with package.json?
Note: command start inside package.json scripts
My json for publish:
{
"name": "name",
"version": "0.0.3",
"description": "Name",
"main": "script.js",
"dependencies": {
"request": "^2.83.0",
},
"devDependencies": {},
"scripts": {
"test": "mocha",
"start": "node node_modules/module/script.js"
},
"repository": {
"type": "git",
"url": "https://github.com/me/module"
},
"keywords": [
"somewords"
],
"author": "me",
"license": "MIT",
"bugs": {
"url": "https://github.com/me/module/issues"
},
"homepage": "https://github.com/me/module#readme"
}
Error (WARN) when installing module on other PC
npm WARN enoent ENOENT: no such file or directory, open '/home/pavlo/Desktop/test/package.json'
npm WARN test No description
npm WARN test No repository field.
npm WARN test No README data
npm WARN test No license field.
But in test/node_modules/module/(here there are everything) readme, json and script
If you want to be able to start your module from another directory, you can do it like this:
In your module package.json
{
"name": "module",
"scripts": {
"start": "node script.js"
}
}
from the test directory (as this answer suggest):
npm start --prefix node_modules/module/
Alternately, you can start your module by creating a package.json file in your test directory and adding a script:
{
"name": "test",
"scripts": {
"start": "node node_modules/module/script.js"
}
}
Usally npm packages are placed in node_modules directory because those modules are supposed to be used as dependencies, not directly.
It depends on the purpose of your application, but maybe you might be interested in doing a post-install script or installing it globally.
npm doc for packages installation.

npm package.json bin chmod error

I have created an npm package and I am trying to install it from a git repository. Everything works fine when I run npm install /path/to/package/ --no-bin-links, but I have my package.json set up to link the main JS file into bin. When I try to install the package normally, I get the following error:
npm ERR! path /staging/webshares/proj-test/node_modules/jkvc-project/index.js
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! enoent ENOENT, chmod '/staging/webshares/proj-test/node_modules/jkvc-project/index.js'
npm ERR! enoent This is most likely not a problem with npm itself
npm ERR! enoent and is related to npm not being able to find a file.
The index.js file definitely exists, and everything in my package.json looks normal:
{
"name": "jkvc-project",
"version": "1.0.0",
"description": "JKD Project Build Tool",
"dependencies": {
"bower": "^1.4.1",
"mkdirp": "^0.5.0",
"optimist": "~0.6.0",
"prompt": "~0.2.12",
"q": "~1.0.0",
"request": "~2.33.0"
},
"files": [
"./scss"
],
"bin": "./index.js"
}
I have tried npm cache clean, but it didn't help. I also have a blank .npmignore file in the directory.
Does anyone know what it causing this chmod error, and how to fix it?
This is the folder structure of my package:
scss
.gitignore
.npmignore
index.js
package.json

Resources