npm install fails with multi-layered local dependencies - npm

npm install doesn't seem to work if I depend on a local package that itself depends on another local package. I'm using npm version 2.5.1.
Here's what I have:
package.json for /src/modules/moduleA:
{
"name": "moduleA",
"version": "0.0.1",
...
"dependencies": {
"bluebird": "^2.9.1",
"nodemailer": "^1.3.0"
}
}
package.json for /src/modules/moduleB:
{
"name": "moduleB",
"version": "1.0.0",
...
"dependencies": {
"nconf": "~0.6.7",
"moduleA": "../moduleA"
}
}
package.json for /src/apps/coolApp:
{
"name": "coolApp",
"version": "1.0.0",
...
"dependencies": {
"mysql": "~2.4.2",
"request": "~2.40.0",
"cheerio": "~0.17.0",
"async": "~0.9.0",
"expand-url": "0.1.3",
"moduleB": "../../modules/moduleB"
}
}
Now if I try to npm install :
cd /src/modules/moduleA
npm install
[success, yay!]
cd /src/modules/moduleB
npm install
[success, yay!]
cd /src/apps/coolApp
npm install
npm ERR! addLocal Could not install /src/node/apps/moduleA
npm ERR! enoent ENOENT, open '/src/node/apps/moduleA'
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.
[oh no!]
For some reason, npm is trying to install moduleA for coolApp, even though it doesn't need to directly, and also, it is using the relative path string as it is literally specified in the package.json file for moduleB, even though that isn't valid for coolApp since it is in a relatively different location.

I found that if you specify the local modules with "file:" before the path, everything works fine. Yay
Like this:
"moduleB": "file:../../modules/moduleB"

Related

what is difference between npm install vs npm install --save?

when I installed node_module on my project.
with npm install
I changed
"dependencies": { "own_module": "github:own_module#v1.0"}
to
"dependencies": { "own_module": "github:own_module#v2.0"}
on package.json.
and execute npm install then, package-lock.json file changed.
but, it's hash value not changed..
"own_module": {
"version": "1.0",
"resolved": "git+ssh://git#github.com/own_module.git#diakvjj"}
to
"own_module": {
"version": "2.0",
"resolved": "git+ssh://git#github.com/own_module.git#diakvjj"}
with npm install --save github:own_module#v2.0"
this changed package.json automatically
"dependencies": { "own_module": "github:own_module#v1.0"}
to
"dependencies": { "own_module": "github:own_module#v2.0"}
and then, package-lock.json file correctly.
"own_module": {
"version": "1.0",
"resolved": "git+ssh://git#github.com/own_module.git#diakvjj"}
to
"own_module": {
"version": "2.0",
"resolved": "git+ssh://git#github.com/own_module.git#awerfd"}
why npm install could not change package-lock.json file automatically?
Now, I use npm#8.3.1 (meaning, version 8)
–save or -S: When the following command is used with npm install this will save all your installed core packages into the dependency section in the package.json file. Core dependencies are those packages without which your application will not give desired results. But as mentioned earlier, it is an unnecessary feature in the npm 5.0.0 version onwards.
read more on this link

Having different errors with vue create and npm run serve

I'm new to vue and I'm having different errors trying to create new projects with vue create and executing npm run serve.
I've already tried reinstalling node and vue. Changed some PATH, but nothing worked.
First I created the application with:
vue create routing-overview
Then i got this in the final part:
added 1259 packages from 656 contributors in 37.319s
🚀 Invoking generators...
📦 Installing additional dependencies...
npm ERR! code EEXIST
npm ERR! path C:\Users\USER\Estudos\igti\m04-vue\routing-overview\node_modules\#babel\parser\bin\babel-parser.js
npm ERR! dest C:\Users\USER\Studies\m04-vue\routing-overview\parser
npm ERR! EEXIST: file already exists, cmd shim 'C:\Users\USER\Studies\m04-vue\routing-overview\node_modules\#babel\parser\bin\babel-parser.js' -> 'C:\Users\USER\Studies\m04-vue\routing-overview\parser'
npm ERR! File exists: C:\Users\USER\Studies\m04-vue\routing-overview\parser
npm ERR! Remove the existing file and try again, or run npm
npm ERR! with --force to overwrite files recklessly.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\USER\AppData\Roaming\npm-cache\_logs\2021-09-10T19_38_16_412Z-debug.log
ERROR command failed: npm install --loglevel error
Opening the project folder on VS Code I have this error in the first import of main.js:
Parsing error: Cannot find module 'babel-eslint'
Require stack:
- C:\Users\USER\Studies\m04-vue\routing-overview\node_modules\vue-eslint-parser\index.js
- C:\Users\USER\Studies\m04-vue\routing-overview\node_modules\eslint-plugin-vue\lib\utils\index.js
- C:\Users\USER\Studies\m04-vue\routing-overview\node_modules\eslint-plugin-vue\lib\rules\array-bracket-newline.js
- C:\Users\USER\Studies\m04-vue\routing-overview\node_modules\eslint-plugin-vue\lib\index.js
- C:\Users\USER\Studies\m04-vue\routing-overview\node_modules\eslint\lib\cli-engine\config-array-factory.js
- C:\Users\USER\Studies\m04-vue\routing-overview\node_modules\eslint\lib\cli-engine\cascading-config-array-factory.js
- C:\Users\USER\Studies\m04-vue\routing-overview\node_modules\eslint\lib\cli-engine\cli-engine.js
- C:\Users\USER\Studies\m04-vue\routing-overview\node_modules\eslint\lib\cli-engine\index.js
- C:\Users\USER\Studies\m04-vue\routing-overview\node_modules\eslint\lib\api.js
- c:\Users\USER\.vscode\extensions\dbaeumer.vscode-eslint-2.1.25\server\out\eslintServer.js
And when I try to npm run serve, i have a different error:
> routing-overview#0.1.0 serve C:\Users\USER\Studies\m04-vue\routing-overview
> vue-cli-service serve
internal/modules/cjs/loader.js:892
throw err;
^
Error: Cannot find module '#vue/cli-plugin-babel'
Require stack:
- C:\Users\USER\Studies\m04-vue\routing-overview\node_modules\#vue\cli-service\lib\Service.js
- C:\Users\USER\Studies\m04-vue\routing-overview\node_modules\#vue\cli-service\bin\vue-cli-service.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:889:15)
at Function.Module._load (internal/modules/cjs/loader.js:745:27)
at Module.require (internal/modules/cjs/loader.js:961:19)
at require (internal/modules/cjs/helpers.js:92:18)
at idToPlugin (C:\Users\USER\Studies\m04-vue\routing-overview\node_modules\#vue\cli-service\lib\Service.js:145:14)
at C:\Users\USER\Studies\m04-vue\routing-overview\node_modules\#vue\cli-service\lib\Service.js:184:20
at Array.map (<anonymous>)
at Service.resolvePlugins (C:\Users\USER\Studies\m04-vue\routing-overview\node_modules\#vue\cli-service\lib\Service.js:170:10)
at new Service (C:\Users\USER\Studies\m04-vue\routing-overview\node_modules\#vue\cli-service\lib\Service.js:32:25)
at Object.<anonymous> (C:\Users\USER\Studies\m04-vue\routing-overview\node_modules\#vue\cli-service\bin\vue-cli-service.js:15:17) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'C:\\Users\\USER\\Studies\\m04-vue\\routing-overview\\node_modules\\#vue\\cli-service\\lib\\Service.js',
'C:\\Users\\USER\\Studies\\m04-vue\\routing-overview\\node_modules\\#vue\\cli-service\\bin\\vue-cli-service.js'
]
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! routing-overview#0.1.0 serve: `vue-cli-service serve`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the routing-overview#0.1.0 serve script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\USER\AppData\Roaming\npm-cache\_logs\2021-09-10T19_48_28_445Z-debug.log
And this is what I have on package.json:
{
"name": "routing-overview",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
"dependencies": {
"core-js": "^3.6.5",
"vue": "^3.0.0"
},
"devDependencies": {
"#vue/cli-plugin-babel": "~4.5.0",
"#vue/cli-plugin-eslint": "~4.5.0",
"#vue/cli-service": "~4.5.0",
"#vue/compiler-sfc": "^3.0.0",
"babel-eslint": "^10.1.0",
"eslint": "^6.7.2",
"eslint-plugin-vue": "^7.0.0"
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/vue3-essential",
"eslint:recommended"
],
"parserOptions": {
"parser": "babel-eslint"
},
"rules": {}
},
"browserslist": [
"> 1%",
"last 2 versions",
"not dead"
]
}
I have no idea what is the problem. Any help is very much appreciated.
Try running:
$ npm install
in the same folder of your package.json file, then try it again.
Have you tried updating npm and node versions?. It's possible you need to update them.
Also, you can try cleaning npm cache data: npm cache clean --force . or you can do it manually by locating appData folder and then \npm-cache folder and delete it. then try running vue create routing-overview again
I was able to fix the problem, even not having a clue about what exactly was wrong.
I uninstalled vue and then Node from my PC. After that, I deleted any trace of node or npm from my PC following the comments from this post.
Then installed Node again and #vue/cli. Used npm init to create a new package.JSON and everything is working as expected right now.
Thanks for the help!

Can't properly configure Autoprefixer in npm scripts

I'm trying to configure PostCSS Autoprefixer but it doesn't work. It should output new style.prefix.css file in the same 'css' folder. Please help me to understand, what is wrong with my npm script/setup
Here is my package.json
{
"name": "sb-demo-website",
"version": "1.0.0",
"description": "demo website",
"main": "index.js",
"scripts": {
"sass": "node-sass-chokidar sass/main.scss css/style.css -w --recursive --skip-initial",
"compile-sass": "node-sass-chokidar sass/main.scss css/style.comp.css",
"prefix-css": "postcss css/style.comp.css -o css/style.prefix.css --use autoprefixer"
},
"repository": {
"type": "git",
"url": ""
},
"author": "tk",
"license": "ISC",
"bugs": {
"url": ""
},
"homepage": "",
"browserslist": "last 3 versions",
"devDependencies": {
"autoprefixer": "^10.0.0",
"node-sass": "^4.14.1",
"node-sass-chokidar": "^1.5.0",
"postcss": "^8.0.5",
"postcss-cli": "^7.1.2"
}
}
and here is output when I run my script:
$ npm run prefix-css
> sb-demo-website#1.0.0 prefix-css C:\Users\tk\Documents\Study\web\css\demo1
> postcss css/style.comp.css -o css/style.prefix.css --use autoprefixer
Error: PostCSS plugin autoprefixer requires PostCSS 8. Update PostCSS or downgrade this plugin.
at Processor.normalize (C:\Users\tk\Documents\Study\web\css\demo1\node_modules\postcss-cli\node_modules\postcss\lib\processor.js:167:15)
at new Processor (C:\Users\tk\Documents\Study\web\css\demo1\node_modules\postcss-cli\node_modules\postcss\lib\processor.js:56:25)
at postcss (C:\Users\tk\Documents\Study\web\css\demo1\node_modules\postcss-cli\node_modules\postcss\lib\postcss.js:55:10)
at C:\Users\tk\Documents\Study\web\css\demo1\node_modules\postcss-cli\index.js:216:14
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! sb-demo-website#1.0.0 prefix-css: `postcss css/style.comp.css -o css/style.prefix.css --use autoprefixer`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the sb-demo-website#1.0.0 prefix-css script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\tk\AppData\Roaming\npm-cache\_logs\2020-09-18T17_50_55_597Z-debug.log
Any help is much appreciated
Looks like latest Autoprefixer v10.0.0 is kinda broken right now. Downgrading it to version 9.8.6 resolved mentioned above issue.
I'm posting this as an answer in case someone else experience similar errors.

npm run build - Insufficient number of arguments or no entry found

I am trying to build a project for the first time and I am getting an error message.
Insufficient number of arguments or no entry found.
Alternatively, run 'webpack(-cli) --help' for usage info.
Hash: 83fdf40d8aadb2841816
Version: webpack 4.18.0
Time: 180ms
Built at: 09/11/2018 4:55:53 AM
ERROR in Entry module not found: Error: Can't resolve './src' in '/home/baudhi/website'
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! website#15.19.1 build: `webpack --mode production`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the website#15.19.1 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/baudhi/.npm/_logs/2018-09-11T11_55_53_650Z-debug.log
The ebook I am reading has asked me to type 'npm run build' but it is not working. any help pls.
My package.json file looks like the following:
{
"name": "website",
"version": "15.19.1",
"description": "just practice",
"main": "main.js",
"scripts": {
"develop": "webpack --mode development --watch",
"build": "webpack --mode production"
},
"author": "pebaudhi",
"license": "ISC",
"devDependencies": {
"webpack": "^4.18.0",
"webpack-cli": "^3.1.0"
},
"dependencies": {
"jquery": "^3.3.1"
}
}
And my directory structure is:
/usr/baudhi/website/.babelrc
/usr/baudhi/website/package.json
/usr/baudhi/website/jquery-3.3.1.js
/usr/baudhi/website/src/main.js
/usr/baudhi/website/dist/main.js
node -v
v10.7.0
Thank you very much for helping me.
If you're using Webpack 4 the configuration has been defaulted. Hence, you don't need to provide a webpack.config.json file but you're project needs to follow the default config.
The default entry point in Webpack 4 is ./src/index.js. So either rename ./src/main.js or create webpack.config.js file with the following minimum.
module.exports = {
entry: './src/main.js'
};

How to package a local npm module?

I am trying to pack an npm package and install it on my webapp.
My application has the following structure:
app
app.ts
app.css
build
app.js
app.css
package.json
tsconfig.json
.npmignore
I started with the pack command documentation.
I added the .npmignore to include only the build folder.
As expected when running npm pack, I know have a new app-1.0.0.tgz
When I try to install it in the web app with npm install ..\typescriptapp\typescriptapp-1.0.0
I get the following error:
npm ERR! code ENOLOCAL
npm ERR! Could not install from
"..\typescriptapp-1.0.0" as it does not contain a
package.json file.
npm ERR! A complete log of this run can be found in: npm ERR!
C:\Users\corbin\AppData\Roaming\npm-cache_logs\2018-03-26T17_49_30_440Z-debug.log
However when I unzip the typescriptapp.tgz, I have the following structure
typecriptapp-1.0.0
typecriptapp-1.0.0
package
build
app.js
app.css
package.json
tsconfig.json
Here is my package.json file:
{
"name": "typescriptapp",
"version": "1.0.0",
"scripts": {
"build": "tsc",
"debug": "tsc -w"
},
"devDependencies": {
"#types/signalr": "2.2.35",
"uglify-js": "3.3.16",
"uglifycss": "0.0.28"
},
"dependencies": {
"#aspnet/signalr": "^1.0.0-preview1-update1",
"lib": "file:../references/lib"
}
}
What am I doing wrong?
You are trying to run install in the parent folder
npm install ..\typescriptapp\typescriptapp-1.0.0
Whereas you have to install it in
npm install ..\typescriptapp\typescriptapp-1.0.0\typescriptapp-1.0.0\package