Postinstall of module is executed before postinstall of sub-module - node.js

Edit:
I'm asking how to install it from GitHub, not npm, that the question.
In case you want to know why: I'm working on some private projects and don't what t publish the code. This leads to the code being in a private repository, not published on npm.
Original post:
Trying to install a module from GitHub (it is in typescript, thus I need a compilation script [postinstall]). It seems to fail because one of the module dependencies is also on GitHub, and that postinstall script is not waited on by the current postinstall script.
Old GitHub issue that sounds related: https://github.com/npm/npm/issues/5001
Yes, like the issue, I also use the same dependency in the main project as the module does.
Program
Version
node
v16.1.0
npm
7.11.2
npm info run newton#1.0.1 postinstall node_modules/newton tsc -d -p .
npm info run nodemon#2.0.7 postinstall node_modules/nodemon node bin/postinstall || exit 0
npm info run rendery#2.0.0 postinstall node_modules/rendery tsc -d -p .
npm info run nodemon#2.0.7 postinstall { code: 0, signal: null }
npm timing build:run:postinstall:node_modules/nodemon Completed in 157ms
npm info run newton#1.0.1 postinstall { code: 0, signal: null }
npm timing build:run:postinstall:node_modules/newton Completed in 2409ms
npm info run rendery#2.0.0 postinstall { code: 2, signal: null }
npm timing reify:rollback:createSparse Completed in 2864ms
npm timing reify:rollback:retireShallow Completed in 0ms
npm timing command:install Completed in 47807ms
npm verb stack Error: command failed
npm verb stack at ChildProcess.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\#npmcli\promise-spawn\index.js:64:27)
npm verb stack at ChildProcess.emit (node:events:365:28)
npm verb stack at maybeClose (node:internal/child_process:1067:16)
npm verb stack at Process.ChildProcess._handle.onexit (node:internal/child_process:301:5)
npm verb pkgid rendery#2.0.0
npm verb cwd C:\Users\Elias\git\natrias
npm verb Windows_NT 10.0.19043
npm verb argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "i" "--verbose" "--force"
npm verb node v16.1.0
npm verb npm v7.11.2
npm ERR! code 2
npm ERR! path C:\Users\Elias\git\natrias\node_modules\rendery
npm ERR! command failed
npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c tsc -d -p .
npm ERR! src/2d/CanvasRenderyContext2D.ts(1,29): error TS2307: Cannot find module 'newton/2d/ReadonlyVector2' or its corresponding type declarations.
npm ERR! src/2d/CanvasRenderyContext2D.ts(2,21): error TS2307: Cannot find module 'newton/2d/Vector2' or its corresponding type declarations.
npm ERR! src/2d/ReadonlyRenderyContext2D.ts(1,29): error TS2307: Cannot find module 'newton/2d/ReadonlyVector2' or its corresponding type declarations.
npm ERR! src/2d/RenderyContext2D.ts(1,29): error TS2307: Cannot find module 'newton/2d/ReadonlyVector2' or its corresponding type declarations.
npm verb exit 2
npm timing npm Completed in 48318ms
npm verb code 2
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Elias\AppData\Local\npm-cache\_logs\2021-05-12T16_19_34_975Z-debug.log
Note that rendery postinstall starts before newton postinstall completes.
Newton package.json
{
"name": "newton",
"version": "1.0.1",
"description": "",
"scripts": {
"lint": "eslint '*/**/*.ts'",
"lint:fix": "eslint '*/**/*.ts' --fix",
"postinstall": "tsc -d -p .",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"devDependencies": {
"#typescript-eslint/eslint-plugin": "^4.22.0",
"#typescript-eslint/parser": "^4.22.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^3.4.0"
},
"dependencies": {
"typescript": "^4.2.4"
}
}
Rendery package.json
{
"name": "rendery",
"version": "2.0.0",
"description": "",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"lint": "eslint '*/**/*.ts'",
"lint:fix": "eslint '*/**/*.ts' --fix",
"postinstall": "tsc -d -p ."
},
"keywords": [],
"devDependencies": {
"#typescript-eslint/eslint-plugin": "^4.22.0",
"#typescript-eslint/parser": "^4.22.0",
"eslint": "^7.25.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-typescript-sort-keys": "^1.6.0"
},
"dependencies": {
"newton": "github:Elias-Graf/newton#main",
"typescript": "^4.2.4"
}
}

It's not a good practice to publish unbuilt packages. I recommend changing the postinstall script into a prepare script so it builds the package before publishing it.
{
"name": "newton",
"version": "1.0.1",
"description": "",
"scripts": {
"lint": "eslint '*/**/*.ts'",
"lint:fix": "eslint '*/**/*.ts' --fix",
"prepare": "tsc -d -p .",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"devDependencies": {
"#typescript-eslint/eslint-plugin": "^4.22.0",
"#typescript-eslint/parser": "^4.22.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^3.4.0"
},
"dependencies": {
"typescript": "^4.2.4"
}
}
{
"name": "rendery",
"version": "2.0.0",
"description": "",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"lint": "eslint '*/**/*.ts'",
"lint:fix": "eslint '*/**/*.ts' --fix",
"prepare": "tsc -d -p ."
},
"keywords": [],
"devDependencies": {
"#typescript-eslint/eslint-plugin": "^4.22.0",
"#typescript-eslint/parser": "^4.22.0",
"eslint": "^7.25.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-typescript-sort-keys": "^1.6.0"
},
"dependencies": {
"newton": "github:Elias-Graf/newton#main",
"typescript": "^4.2.4"
}
}
This would fix your issue.

Related

Failed npm run dev with Tailwindcss

I just follow instruction from this youtube video https://youtu.be/lhCGoQkya5Q but i cant running npm run dev
in terminal:
PS C:\Users\Turtle\Desktop\My Site> npm run dev
npm ERR! Missing script: "dev"
npm ERR!
npm ERR! To see a list of scripts, run:
npm ERR! npm run
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Turtle\AppData\Local\npm-cache\_logs\2022-02-22T19_13_01_984Z-debug-0.log
Project\css\tailwind.css
#tailwind base;
#tailwind components;
#tailwind utilities;
package.json
{
"name": "my-site",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"autoprefixer": "^10.4.2",
"postcss": "^8.4.6",
"tailwindcss": "^3.0.23",
"vite": "^2.8.4"
}
}
You have to add a new key in your scripts key
"scripts": {
"dev": "npx tailwindcss -i ./css/tailwind.css -o ./dist/style.css --watch",
"test": "echo \"Error: no test specified\" && exit 1"
},
./css/tailwind.css is your sour; change the name according.ly
./dist/style.css is your dist path/filename
--watch is to keep running and watch when you change something in your code

How to fix NPM EJSONParse with this package.json file?

when I try the command npm install I have this
C:\Users\khaou>npm install
npm ERR! code EJSONPARSE
npm ERR! path C:\Users\khaou/package.json
npm ERR! JSON.parse Unexpected end of JSON input while parsing empty string
npm ERR! JSON.parse Failed to parse JSON data.
npm ERR! JSON.parse Note: package.json must be actual JSON, not just JavaScript.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\khaou\AppData\Local\npm-cache\_logs\2021-12-31T16_42_25_903Z-debug.log
This is the JSON:
{
"name": "eth-todo-list",
"version": "1.0.0",
"description": "Blockchain Todo List Powered By Ethereum",
"main": "truffle-config.js",
"directories": {
"test": "test"
},
"scripts": {
"dev": "lite-server",
"test": "echo \"Error: no test specified\" && sexit 1"
},
"author": "gregory#dappuniversity.com",
"license": "ISC",
"devDependencies": {
"bootstrap": "4.1.3",
"chai": "^4.1.2",
"chai-as-promised": "^7.1.1",
"chai-bignumber": "^2.0.2",
"lite-server": "^2.3.0",
"nodemon": "^1.17.3",
"truffle": "5.0.2",
"truffle-contract": "3.0.6"
}
}
Probably your file association is other than JavaScript like JavaScript react or any other.
Check your package.json settings file to have Item:javascript Value:javascript as default extension (*) on Files:Associations.
package.json->file->preferences->settings->Files:Associations
Item:javascript Value:javascript
Hope it works!

how to fix this npm start not working ( after npx create-react-app )

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! todos-clone-app#0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the todos-clone-app#0.1.0 start 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/josh/.npm/_logs/2020-08-21T19_28_35_521Z-debug.log
Edit:
package.json
{
"name": "todos-clone-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"#testing-library/jest-dom": "^4.2.4",
"#testing-library/react": "^9.5.0",
"#testing-library/user-event": "^7.2.1",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-scripts": "3.4.3",
"webpack-dev-server": "^3.11.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [ ">0.2%", "not dead", "not op_mini all" ],
"development": [ "last 1 chrome version", "last 1 firefox version", "last 1 safari version" ]
}
}
Try deleting your node_modules directory and package-lock.json file. Then run npm install.
In my case, it was because of not being in the right folder.
Generally, I create a folder and go to Vs code to open it for typing create-react-app "folder name" to the console.
The problem was I was trying to npm start in parent folder instead of "folder name".
All you have to do is:
cd folder_name
npm start
Try:
npx create-react-app ./
It worked for me.

How to fix NPM EJSONParse in this package.json file?

After I prepared for auto scripts and installing few packages to automate my tasks, I got the following error:
npm ERR! file C:\Users\windw\Desktop\bootstrap4\package.json
npm ERR! code EJSONPARSE
npm ERR! JSON.parse Failed to parse json
npm ERR! JSON.parse Unexpected string in JSON at position 455 while parsing '{
npm ERR! JSON.parse "name": "confusion",
npm ERR! JSON.parse "version": '
npm ERR! JSON.parse Failed to parse package.json data.
npm ERR! JSON.parse package.json must be actual JSON, not just JavaScript.
Below is my package.json file
{
"name": "confusion",
"version": "1.0.0",
"description": "This is a website for Ristorante Con Fusion",
"main": "index.html",
"scripts": {
"start": "npm run watch:all",
"test": "echo \"Error: no test specified\" && exit 1",
"lite": "lite-server",
"scss": "node-sass -o css/ css/",
"watch:scss": "onchange \"css/*.scss\" -- npm run scss",
"watch:all": "parallelshell \"npm run watch:scss\" \"npm run lite\""
"clean": "rimraf dist",
"copyfonts": "copyfiles -f node_modules/font-awesome/fonts/* dist/fonts",
"imagemin": "imagemin img/* --out-dir='dist/img'",
"usemin": "usemin contactus.html -d dist --htmlmin -o dist/contactus.html && usemin aboutus.html -d dist --htmlmin -o dist/aboutus.html && usemin index.html -d dist --htmlmin -o dist/index.html",
"build": "npm run clean && npm run imagemin && npm run copyfonts && npm run usemin"
},
"author": "",
"license": "ISC",
"devDependencies": {
"cssmin": "^0.4.3",
"htmlmin": "0.0.7",
"lite-server": "^2.3.0",
"node-sass": "^4.7.2",
"onchange": "^6.1.0",
"parallelshell": "^3.0.2",
"rimraf": "^2.6.2",
"uglifyjs": "^2.4.11",
"usemin-cli": "^0.5.1"
},
"dependencies": {
"bootstrap": "^4.3.1",
"bootstrap-social": "5.1.1",
"font-awesome": "4.7.0",
"jquery": "^3.4.1",
"popper.js": "1.12.9"
}
}
How can I fix the NPM EJSONParse error?
You are missing a comma at the end of the 12th line in your package.json file.
Presently it looks like this:
"watch:all": "parallelshell \"npm run watch:scss\" \"npm run lite\""
It should look like this:
"watch:all": "parallelshell \"npm run watch:scss\" \"npm run lite\"",
Note the comma at the end of the line.
This error occurred when you are somehow missing "," comma. and when you use comma in last line if not required also it happens. If this issue showed, you need to review your pakage.json file.

npm run start with "DEBUG=*" issue on Windows

{
"name": "apokidsi",
"version": "0.717",
"contributors": [
],
"dependencies": {
"angular": "1.5.8",
"angular-cookies": "1.5.8",
"angular-messages": "1.5.8",
"angular-ui-router": "1.0.0-beta.3",
"debug": "^3.0.0",
"flag-icon-css": "2.8.0",
"jquery": "3.2.1",
"moment": "2.18.1",
"moment-timezone": "0.5.13",
"node-fetch-npm": "^2.0.1"
},
"scripts": {
"clean": "gulp clean",
"start": "DEBUG=true HOST=localhost:4200 gulp server",
}
}
Here is the package.json file.
When I run npm run start
I get this message
'DEBUG' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
After checking all the possibilities we have to use the cross-env dependencies.
so install npm install cross-env --save-dev
and in package.json
"Start": " cross-env-shell DEBUG=True HOST=dev.example.com gulp server"

Resources