error: Cannot find module 'postcss' heroku - node.js

The website works fine on local, but it fails to deploy on Heroku with a very common error. I am using direct deploy from Github.
node:internal/modules/cjs/loader:936
throw err;
^
Error: Cannot find module 'postcss'
Require stack:
- /tmp/build_d7cb8562/node_modules/postcss-cli/index.js
- /tmp/build_d7cb8562/node_modules/postcss-cli/bin/postcss
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (/tmp/build_d7cb8562/node_modules/postcss-cli/index.js:14:17)
at Module._compile (node:internal/modules/cjs/loader:1105:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/tmp/build_d7cb8562/node_modules/postcss-cli/index.js',
'/tmp/build_d7cb8562/node_modules/postcss-cli/bin/postcss'
]
}
ERROR: "prefix:css" exited with 1.
-----> Build failed
This is my package.json file before I tried fixing it by moving devDependencies to dependencies
{
"name": "dopefolio",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"compile:scss": "node-sass sass/main.scss css/style.css -w",
"prefix:css": "postcss --use autoprefixer -b 'last 10 versions' css/style.css -o css/style.css",
"compress:css": "node-sass css/style.css css/style.css --output-style compressed",
"build": "npm-run-all prefix:css compress:css"
},
"author": "",
"license": "GPL-3.0",
"devDependencies": {
"autoprefixer": "^10.3.1",
"node-sass": "^6.0.1",
"npm-run-all": "^4.1.5",
"postcss-cli": "^8.3.1"
}
}
This is my attempted fix:
{
"name": "dopefolio",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"autoprefixer": "^10.3.1",
"node-sass": "^6.0.1",
"npm-run-all": "^4.1.5",
"postcss-cli": "^8.3.1"
},
"scripts": {
"compile:scss": "node-sass sass/main.scss css/style.css -w",
"prefix:css": "postcss --use autoprefixer -b 'last 10 versions' css/style.css -o css/style.css",
"compress:css": "node-sass css/style.css css/style.css --output-style compressed",
"build": "npm-run-all prefix:css compress:css"
},
"author": "",
"license": "GPL-3.0",
"devDependencies": {
}
}
It still fails to deploy with the same error. What could be the case?

Related

npm not start. Error: Cannot find module 'webpack-cli/bin/config-yargs'

when I give npm start comand its show
internal/modules/cjs/loader.js:883
throw err:
Error: Cannot finde module'webpack-cli/bin/config-yargs'
plz help me to solve this problem
use os : windows 10
node version is v14.16.1
> chapter15.1#1.0.0 start
> webpack-dev-server
internal/modules/cjs/loader.js:883
throw err;
^
Error: Cannot find module 'webpack-cli/bin/config-yargs'
Require stack:
- C:\Users\user\Desktop\JS full Course\chapter15.1\node_modules\webpack-dev-server\bin\webpack-dev-server.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
at Function.Module._load (internal/modules/cjs/loader.js:725:27)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.<anonymous> (C:\Users\user\Desktop\JS full Course\chapter15.1\node_modules\webpack-dev-server\bin\webpack-dev-server.js:65:1)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'C:\\Users\\user\\Desktop\\JS full Course\\chapter15.1\\node_modules\\webpack-dev-server\\bin\\webpack-dev-server.js'
]
}
webpack version 5.37.1
webpack-cli version 4.7.0
webpack-dev-server version 3.11.2
Package.json file is
{
"name": "chapter15.1",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "webpack-dev-server"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"#babel/cli": "^7.14.3",
"#babel/core": "^7.14.3",
"#babel/node": "^7.14.2",
"#babel/polyfill": "^7.12.1",
"#babel/preset-env": "^7.14.2",
"#babel/register": "^7.13.16",
"babel-loader": "^8.2.2",
"babel-register": "^6.26.0",
"html-webpack-plugin": "^5.3.1",
"webpack": "^5.37.1",
"webpack-cli": "^4.7.0",
"webpack-dev-server": "^3.11.2"
}
}
In the Package.json file add a serve script like below and remove the start script. See the documentation.
{
"scripts": {
"serve": "webpack serve"
},
Then Run this command in your terminal.
npm run serve

React app, cannot find library, which I have installed manually

I am building a React app. I installed yargs and argsert manually by npm. For some reason, when I start the development server, I get the following error and stack trace. The two modules in question are listed clearly as argsert and yargs. I am unsure of how to proceed. Any feedback would be greatly appreciated.
webpack-dev-server --mode development
module.js:549
throw err;
^
Error: Cannot find module './lib/argsert'
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/home/josh/devel/react-app/frontend/node_modules/webpack-dev-server/node_modules/yargs/yargs.js:2:17)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
package.json
{
"name": "react-app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "webpack-dev-server --mode development",
"build": "webpack --mode production",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"#babel/core": "^7.8.7",
"#babel/preset-env": "^7.8.7",
"#babel/preset-react": "^7.8.3",
"babel-loader": "^8.0.6",
"html-loader": "^0.5.5",
"html-webpack-plugin": "^3.2.0",
"webpack": "^4.42.0",
"webpack-cli": "^3.3.11",
"webpack-dev-server": "^3.10.3"
},
"dependencies": {
"argsert": "^1.0.9",
"babel-loader": "^8.0.6",
"react": "^16.13.0",
"react-dom": "^16.13.0",
"react-router-dom": "^5.1.2",
"weak-key": "^1.0.1",
"yargs": "^15.3.1"
}
}
Use npm i argsert yargs if it is not working working try to npm install if even tough it is not working. Delete argsert and yargs from package.json and install it again.
I have installed node and npm from source and that seems to have fixed the issue. Thanks for the help everyone.

npm run start:dev cannot find module

npm run start works fine, but npm run start: dev throws this error:
7:14:22 PM - Found 0 errors. Watching for file changes.
internal/modules/cjs/loader.js:638
throw err;
^
Error: Cannot find module 'src/models/note.model'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.<anonymous> (C:\Users\Anuitex-169\Desktop\VersF\nest\server\dist\note\note.service.js:17:22)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
This error appeared from the very beginning of my project, and I can’t understand why. I decided to forget about this problem since npm run start works well. But somehow uncomfortable (
My app.module.ts
My package.json file:
{
"name": "server",
"version": "0.0.1",
"description": "",
"author": "",
"license": "MIT",
"scripts": {
"build": "rimraf dist && tsc -p tsconfig.build.json",
"format": "prettier --write \"src/**/*.ts\"",
"start": "ts-node -r tsconfig-paths/register src/main.ts",
"start:dev": "tsc-watch -p tsconfig.build.json --onSuccess \"node dist/main.js\"",
"start:debug": "tsc-watch -p tsconfig.build.json --onSuccess \"node --inspect-brk dist/main.js\"",
"start:prod": "node dist/main.js",
"lint": "tslint -p tsconfig.json -c tslint.json",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json"
},
"dependencies": {
"#nestjs/common": "^6.0.0",
"#nestjs/core": "^6.0.0",
"#nestjs/platform-express": "^6.0.0",
"#nestjs/typeorm": "^6.1.3",
"mongodb": "^3.3.2",
"path": "^0.12.7",
"reflect-metadata": "^0.1.12",
"rimraf": "^2.6.2",
"rxjs": "^6.3.3",
"typeorm": "^0.2.19"
},
"devDependencies": {
"#nestjs/testing": "^6.0.0",
"#types/express": "4.16.1",
"#types/jest": "24.0.11",
"#types/multer": "^1.3.10",
"#types/node": "11.13.4",
"#types/supertest": "2.0.7",
"jest": "24.7.1",
"prettier": "1.17.0",
"supertest": "4.0.2",
"ts-jest": "24.0.2",
"ts-node": "8.1.0",
"tsc-watch": "2.2.1",
"tsconfig-paths": "3.8.0",
"tslint": "5.16.0",
"typescript": "3.4.3"
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": ".",
"roots": [
"<rootDir>/src/",
"<rootDir>/libs/",
"<rootDir>/apps/"
],
"testRegex": ".spec.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"coverageDirectory": "./coverage",
"testEnvironment": "node"
}
}
Please help me deal with this problem.
Your AppModule looks fine, so I have to wonder if something is happening in your NoteService, which this line makes it looks like that is the case at Object.<anonymous> (C:\Users\Anuitex-169\Desktop\VersF\nest\server\dist\note\note.service.js:17:22).
If I had to bet, you are trying to read the module from your src directory while you are in your dist directory (at least by standard Typescript compilation). Instead of using an import like src/models/note.model you should use an import that takes into account the path from the current file (such as ../models/note.model). You may need to change that a bit more, but that's the idea of what should happen

log4js is not working on gae with nodejs

I am trying to deploy node project on google app engine using
gcloud app deploy
But this is throwing error
Updating service [default]...failed.
ERROR: (gcloud.app.deploy) Error Response: [9]
Application startup error:
module.js:471
throw err;
^
Error: Cannot find module 'log4js'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/app/server.js:38:14)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
The same project is working on local machine. Here is my package.json
{
"name": "myapp",
"version": "1.0.0",
"description": "myapp",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": ""
},
"author": "",
"license": "ISC",
"bugs": {
"url": ""
},
"homepage": "",
"dependencies": {
"body-parser": "^1.15.0",
"connect-timeout": "^1.8.0",
"express": "^4.13.4",
"generic-pool": "^2.4.2",
"multer": "^1.2.0",
"mysql": "^2.10.2",
"requestify": "^0.1.17"
}
}
What is the issue?
log4js is missing in your dependencies.
npm install log4js --save to add it to your package.json.

how to start global npm module with harmony flag

I wrote a npm module which can be installed globally dm-npm.
I like to use co in that module.
How can i told the module that it runs with the harmony flag when started globally?
Here is the package.json:
{
"name": "dm-npm",
"version": "0.0.3",
"description": "npm helper",
"main": "index.js",
"scripts": {
"test": "mocha --reporter nyan",
"start": "node --harmony ./bin/dm-npm"
},
"repository": {
"type": "git",
"url": "https://github.com/divramod/dm-npm.git"
},
"keywords": [
"npm",
"template"
],
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/divramod/dm-npm/issues"
},
"homepage": "https://github.com/divramod/dm-npm",
"devDependencies": {
"chai": "^2.1.0",
"mocha": "^2.1.0"
},
"dependencies": {
"co": "^4.4.0",
"co-prompt": "^1.0.0",
"colors": "~1.0.3",
"shelljs": "^0.3.0"
},
"bin": {
"dmnpm": "./bin/dm-npm"
}
}
i got the following error message when running with a co function:
> $ dmnpm init
/usr/local/lib/node_modules/dm-npm/index.js:152
co(function*() {
^
SyntaxError: Unexpected token *
at exports.runInThisContext (vm.js:73:16)
at Module._compile (module.js:443:25)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (/usr/local/lib/node_modules/dm-npm/bin/dm-npm:3:1)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
it is caused by
co(function*() {
var projectName =
yield prompt('project name: '.blue);
process.stdin.pause();
});
#!/usr/bin/env node --harmony
on the top of script works for me, in your case in /bin/dm-npm

Resources