Npm searching for package.json in the wrong directory - javascript

Hey I'm trying to install webpack right now.
I have everything setup, but when I try to run webpack inside my terminal, it searches for the package.json file in the wrong directory.
So my question is, can I change the path where npm tries to find my package.json file?
npm ERR! enoent ENOENT: no such file or directory, open '/home/User/package.json
^error message I get after trying to run npm webpack in Terminal
{
"name": "package",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"es6-promise": "^4.1.1",
"react": "^16.2.0",
"react-dom": "^16.2.0"
}
}
^this is the package.json file from my project

You are in the wrong directory.
Make sure you are in the right folder and then run npm install webpack.
In your terminal use pwd to print the current working directory and then ls to list all the files inside it. If there is no package.json you can't install anything.

Related

Local npm install from file path not working

I followed Link to install the npm package from the file path
However, when I try to use it I am getting the following error.
Cannot file moduele '<module_name>' or its corresponding type declaration
Is there any tutorial to follow in order to install typescript-based npm package locally?
Here my package.json of the package i want to install
{
"name": "sqs",
"version": "1.0.0",
"description": "",
"main": "src/index.ts",
"types": "dist/index.d.ts",
"scripts": {
"build": "rm -rf build && prettier --write src/ && tsc",
"start": "ts-node ./src/index.ts",
"start:prod": "npm run build && node ./dist/src/index.js",
"start:dev": "./node_modules/nodemon/bin/nodemon.js",
"lint": "eslint '*/**/*.{js,ts,tsx}'",
"lint:fix": "eslint --fix '*/**/*.{js,ts,tsx}'",
"prettier": "prettier -c ./src/**/*.{js,ts,tsx,scss,css,md}",
"prettier:fix": "prettier -c ./src/**/*.{js,ts,tsx,scss,css,md} --write"
},
"author": "Rohit Sthapit",
"license": "ISC",
"dependencies": {
"aws-sdk": "^2.820.0",
"nodemon": "^2.0.20",
"readline-sync": "^1.4.10",
"ts-node": "^10.9.1"
},
"devDependencies": {
"#types/dotenv": "^8.2.0",
"#typescript-eslint/eslint-plugin": "^5.36.2",
"#typescript-eslint/parser": "^5.36.2",
"dotenv": "^8.2.0",
"eslint": "^8.23.1",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.2.1",
"prettier": "^2.7.1"
}
}
Usually for packages that support typescript, you would find a DT symbol when you open the package page in npm.
For installing the typescript package, you use npm i #types/{package_name}. For eg, in lodash's case you could do:
npm i #types/lodash
Hope it helps!!
use this,
npm install --save-dev #types/package-name

TypeORM error when trying to create migration in CLI

I'm trying to use the TypeORM CLI to create a migration. I followed their guide but when I run yarn run typeorm migration:generate I get the error:
$ typeorm-ts-node-commonjs migration:generate
/usr/bin/env: ‘node --require ts-node/register’: No such file or directory
/usr/bin/env: use -[v]S to pass options in shebang lines
error Command failed with exit code 127.
My package.json looks like this:
{
"name": "server",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"watch": "tsc -w",
"start": "node dist/index.js",
"dev": "nodemon dist/index.js",
"start2": "ts-node src/index.ts",
"dev2": "nodemon --exec ts-node src/index.ts",
"typeorm": "typeorm-ts-node-commonjs"
},
"author": "",
"license": "ISC",
"dependencies": {
"apollo-server-express": "^3.6.7",
"class-validator": "^0.13.2",
"cors": "^2.8.5",
"express": "^4.17.3",
"express-graphql": "^0.12.0",
"graphql": "^15.3.0",
"pg": "^8.7.3",
"reflect-metadata": "^0.1.13",
"ts-node": "^10.7.0",
"type-graphql": "^1.1.1",
"typeorm": "^0.3.4"
},
"devDependencies": {
"#types/express": "^4.17.13",
"#types/node": "^17.0.23",
"nodemon": "^2.0.15",
"typescript": "^4.6.3"
}
}
I managed to solve this by installing the cli as described here https://orkhan.gitbook.io/typeorm/docs/using-cli#installing-cli
Install ts-node globally npm install -g ts-node
add the following script to package.json: "typeorm": "node --require ts-node/register ./node_modules/typeorm/cli.js" instead of "typeorm": "typeorm-ts-node-commonjs"
then create a migration with:
yarn run typeorm migration:generate -p -d src/data-source.ts src/migrations/<filename without ending>
FYI For anyone facing similar issues: It took me a while to figure out that the various documentations on typeorm are confusing and conflicting at the moment because they just moved to v0.3.0 and not everything has been updated.

Error: "'node' not recognized as..." when I try to run the file with package.json script [duplicate]

This question already has answers here:
'node' is not recognized as an internal or an external command, operable program or batch file while using phonegap/cordova
(19 answers)
Closed last year.
I am learning Node, and I get the error "node is not recognized as an internal or external command" when I try to run my project with npm start or npm run start. It works if I use node index.js. I have checked the Node Environment Variables, my Node version is v16.13.2 and npm is 8.4.1.
My package.json:
{
"name": "node-express-practica",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"license": "ISC",
"devDependencies": {
"#babel/cli": "^7.17.0",
"#babel/core": "^7.17.2",
"#babel/preset-env": "^7.16.11",
"#babel/register": "^7.17.0",
"nodemon": "^2.0.15"
}
}
Running command as administrator should work for you.

How to delete a

I created an npm link inside a local dependency. I've since deleted that local dependency off my HDD.
Now I'm trying to delete this npm link.
I've tried:
npm rm --global dependency
npm uninstall dependency
npm unlink --no-save dependency
However, after doing all that, and after the code has been deleted from my HDD, npm link dependency still works when called from my main project. How to delete it properly? Here's my package.json:
{
"name": "myproject",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "webpack serve",
"build": "webpack --mode production"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"copy-webpack-plugin": "^9.0.1",
"d3-array": "^3.0.1",
"d3-dsv": "^3.0.1",
"d3-format": "^3.0.1",
"d3-scale": "^4.0.0",
"d3-time-format": "^4.0.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"typescript": "^4.3.5"
},
"devDependencies": {
"#types/d3-array": "^3.0.1",
"#types/d3-dsv": "^3.0.0",
"#types/d3-format": "^3.0.1",
"#types/d3-scale": "^4.0.1",
"#types/d3-time-format": "^4.0.0",
"#types/react-dom": "^17.0.9",
"html-webpack-plugin": "^5.3.2",
"ts-loader": "^9.2.3",
"webpack": "^5.44.0",
"webpack-cli": "^4.7.2",
"webpack-dev-server": "^3.11.2"
}
}
Can you post your package.json ?
Weird, this should works
npm unlink dependency
rm -rf node_modules && npm install
It was asked here How do I uninstall a package installed using npm link?
UPD
Can remove symlink from global node_modules.
Find where is global npm list -g and remove it
rm -rf `npm list -g | head -1`/node_modules/dependency

Webpack installation issue

I wanted to setup webpack and babel with npm, but I got this error
npm ERR! Unexpected end of JSON input while parsing near '...pdragon":"^0.7.0","to' npm ERR! A complete log of this run can be found in:
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\luchan.vladyslav\AppData\Roaming\npm-cache\_logs\2017-12-10T10_48_56_298Z-debug.log
here is my package.json
{
"name": "ddd",
"version": "1.0.0",
"description": "components",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-preset-env": "^1.6.1"
}
}
At the begining I have tried to install webpack webpack-dev-server babel-core babel-loader and babel-preset-env in one line. But I got this error, after a while I figured out that problem is related to webpack and wepback-dev-server
screenshot
Looks like the corrupt local node_modules is to be blamed. Can you remove the local node_modules folder and then freshly install by `npm install' ? That should fix the issue.
To solve this problem you should clean your cache with
npm cache clean --force
That will solve the problem

Categories

Resources