Found the error when I deploy the next.js app in cPannal - deployment

I want to deploy my next.js app in cPannel. I follow all the steps but I received the errors in the stderr.log file. the errors is
internal/modules/cjs/loader.js:905
throw err;
^
Error: Cannot find module 'next'
Require stack:
- /home/yourhikf/dev.yourguide.pk/server.js
- /usr/local/lsws/fcgi-bin/lsnode.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
at Function.Module._load (internal/modules/cjs/loader.js:746:27)
at Module.require (internal/modules/cjs/loader.js:974:19)
at require (internal/modules/cjs/helpers.js:93:18)
at Object.<anonymous> (/home/yourhikf/dev.yourguide.pk/server.js:4:14)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:12)
at Module.require (internal/modules/cjs/loader.js:974:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/home/yourhikf/dev.yourguide.pk/server.js',
'/usr/local/lsws/fcgi-bin/lsnode.js'
]
}
This is the error that is logged when I want to load the deployed site. The package.json file has the following packages
{
"name": "yourguide-next-frontend",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "node server.js",
"build": "next build",
"start": "NODE_ENV=production node server.js"
},
"dependencies": {
"#emotion/react": "^11.9.3",
"#emotion/styled": "^11.9.3",
"#mui/material": "^5.9.2",
"#tinymce/tinymce-react": "^4.2.0",
"cookies": "^0.8.0",
"js-cookie": "^3.0.1",
"next": "12.2.3",
"react": "18.2.0",
"react-bootstrap": "^2.4.0",
"react-dom": "18.2.0",
"tinymce": "^6.1.2"
},
"devDependencies": {
"eslint": "8.20.0",
"eslint-config-next": "12.2.3"
}
}
I am unable to solve the problem kindly tell me the solution of my problem.

I solved it by entering the following commands in the terminal:
npm update
npm install

Related

how to solve mongoParseError in nodeModule?

this is output after run yarn start having this is the error:
`yarn run v1.22.17
warning ../../../package.json: No license field
$ ts-node index.ts
MongoParseError: Invalid scheme, expected connection string to start with "mongodb://" or "mongodb+srv://"
at new ConnectionString (/Users/youmnasalloum/Desktop/ts/user/node_modules/mongodb-connection-string-url/src/index.ts:133:13)
at parseOptions (/Users/youmnasalloum/Desktop/ts/user/node_modules/mongoose/node_modules/mongodb/src/connection_string.ts:253:15)
at new MongoClient (/Users/youmnasalloum/Desktop/ts/user/node_modules/mongoose/node_modules/mongodb/src/mongo_client.ts:337:34)
at /Users/youmnasalloum/Desktop/ts/user/node_modules/mongoose/lib/connection.js:783:16
at new Promise (<anonymous>)
at NativeConnection.Connection.openUri (/Users/youmnasalloum/Desktop/ts/user/node_modules/mongoose/lib/connection.js:780:19)
at Mongoose.createConnection (/Users/youmnasalloum/Desktop/ts/user/node_modules/mongoose/lib/index.js:285:10)
at Object.<anonymous> (/Users/youmnasalloum/Desktop/ts/user/db/index.ts:9:28)
at Module._compile (node:internal/modules/cjs/loader:1103:14)
at Module.m._compile (/Users/youmnasalloum/Desktop/ts/user/node_modules/ts-node/src/index.ts:1455:23)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
make: *** [start] Error 1`
this is package.json:
{ "name": "user", "version": "1.0.0", "main": "index.ts", "repository": "https://github.com/ArtistCrowdfundExchange/user", "author": "Oghogho Odemwingie", "license": "MIT", "devDependencies": { "#types/bcrypt": "^3.0.0", "#types/node": "^17.0.13", "typescript": "4.5.5" }, "scripts": { "start": "ts-node index.ts", "test": "echo no tests yet" }, "dependencies": { "#aws-sdk/client-s3": "^3.41.0", "#grpc/grpc-js": "^1.3.7", "amqp": "^0.2.7", "aws4": "^1.11.0", "bcrypt": "^5.0.0", "cuid": "^2.1.8", "encrypter": "^1.0.0", "erax.db": "^3.3.1", "jose": "3", "mongodb": "^4.5.0", "mongodb-uri": "^0.9.7", "mongoose": "6.1.8", "nanoid": "^3.1.29", "proto": "git+https://github.com/ArtistCrowdfundExchange/proto#playground", "ts-node": "^10.4.0", "winston": "^3.3.3", "yael-autoencrypt": "^1.1.0" } }
I tried to add packages mongo-Uri,mongo-connection-string-URI using yarn but still the same error when I do yarn start

error: agent ??= new https.Agent({ ...this.client.options.http.agent, keepAlive: true });

I'm trying to host my Discord bot but I keep receiving this error message:
agent ??= new https.Agent({ ...this.client.options.http.agent, keepAlive: true });
^^^
SyntaxError: Unexpected token '??='
at wrapSafe (internal/modules/cjs/loader.js:1001:16)
at Module._compile (internal/modules/cjs/loader.js:1049:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:12)
at Module.require (internal/modules/cjs/loader.js:974:19)
at require (internal/modules/cjs/helpers.js:93:18)
at Object.<anonymous> (/app/node_modules/discord.js/src/rest/RESTManager.js:4:20)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
package.json file:
{
"name": "gifuploader",
"version": "1.0.0",
"description": "",
"main": "main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/UnidentifiedGithubDeveloper/gifuploader.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/UnidentifiedGithubDeveloper/gifuploader/issues"
},
"homepage": "https://github.com/UnidentifiedGithubDeveloper/gifuploader#readme",
"dependencies": {
"discord.js": "^13.2.0"
}
}
I've already installed the latest v16 version, and ran all of the discord.js updates on my project but it still returns the same error.

babel v7 upgrade causing unexpected token import in files imported by related path and in plugin-transform-runtime

After upgrading to 7 none of the googled answers not working.
I have a project structure
package.json
"scripts": {
"start": "yarn dev:start",
"restart": "touch src/shared/app.jsx",
"dev:start": "cross-env BABEL_ENV=dev nodemon -e js,jsx --watch src/server --exec babel-node src/server",
"dev:wds": "cross-env BABEL_ENV=dev webpack-dev-server --progress --info-verbosity verbose",
"prod:build": "rimraf lib dist && babel src -d lib --ignore .test.js && cross-env NODE_ENV=production webpack -p --progress --color --display-error-details",
"prod:start": "cross-env NODE_ENV=production pm2 start lib/server && pm2 logs",
"prod:stop": "pm2 delete server",
"lint": "eslint src webpack.config.babel.js --ext .js,.jsx",
"test": "yarn lint && flow && jest --coverage",
"precommit": "yarn test",
"prepush": "yarn test && yarn prod:build"
},
"devDependencies": {
"#babel/cli": "^7.8.4",
"#babel/core": "^7.0.0",
"#babel/node": "^7.0.0",
"#babel/plugin-proposal-class-properties": "^7.0.0",
"#babel/plugin-proposal-json-strings": "^7.0.0",
"#babel/plugin-syntax-dynamic-import": "^7.8.3",
"#babel/plugin-syntax-import-meta": "^7.0.0",
"#babel/plugin-transform-modules-commonjs": "^7.8.3",
"#babel/plugin-transform-runtime": "^7.8.3",
"#babel/preset-env": "^7.0.0",
"#babel/preset-flow": "^7.0.0",
"#babel/preset-react": "^7.0.0",
"#babel/register": "^7.8.3",
"#gfx/zopfli": "^1.0.10",
"babel-core": "^7.0.0-bridge.0",
"babel-eslint": "^9.0.0",
"babel-jest": "^23.4.2",
"babel-loader": "^8.0.0",
"babel-plugin-flow-react-proptypes": "^4.1.0",
"babel-plugin-lodash": "^3.3.4",
"babel-plugin-recharts": "^1.2.0",
"babel-plugin-transform-react-remove-prop-types": "^0.4.14",
"babel-plugin-webpack-alias": "^2.1.2",
"compression-webpack-plugin": "^2.0.0",
"cross-env": "^5.2.0",
"css-loader": "^0.28.5",
"html-webpack-plugin": "^3.2.0",
"isomorphic-style-loader": "^4.0.0",
"jest": "^20.0.4",
"lodash-webpack-plugin": "^0.11.5",
"sass-loader": "^6.0.6",
"style-loader": "^0.18.2",
"url-loader": "^0.5.9",
"webpack": "^4.22.0",
"webpack-cli": "^3.1.2",
"webpack-dev-server": "^3.10.3"
},
"dependencies": {
"#babel/core": "^7.0.0",
"#babel/plugin-proposal-object-rest-spread": "^7.0.0",
"#babel/runtime": "^7.3.4",
"#babel/runtime-corejs3": "^7.4.3",
"babel-plugin-transform-imports": "^1.5.0",
"core-js": "^3.6.4",
"webpack-spritesmith": "^0.4.1"
}
babel.config.json
{
"presets": [
[
"#babel/preset-env",
{
"useBuiltIns": "usage",
"corejs": {
"version": 3,
"proposals": true
},
"debug": true
}
],
"#babel/preset-flow",
"#babel/preset-react"
],
"plugins": [
"lodash",
"flow-react-proptypes",
"#babel/plugin-proposal-object-rest-spread",
"#babel/plugin-proposal-class-properties",
[
"transform-imports",
{
"react-router": {
"transform": "react-router/${member}",
"preventFullImport": true
}
}
],
[
"#babel/plugin-transform-runtime",
{
"corejs": 3,
"helpers": true,
"useESModules": true
}
]
]
}
First babel doesn't transpile plugin-transform-runtime (or perhaps any file in node_modules)
After babel-node src/server
Got an error Unexpeted token import
Second If i turn off plugin-transform-runtime, everything is fine, until babel meet a
relative imported file and import in it
Every others import constructions don't lead to such errors
imported file causing error importing in it
Error just here
Whatever packages i've been installed, whatever config files neither .babelrc nor babel.config.json - not working, in babel 6 have no problems
Is it rooting or structure issues, or maybe config?
Tried to re-install all packages, clearing cache. Same error
However, prod:build aka babel src -d lib is working fine, but webpack then crushed on same
\node_modules\#babel\runtime-corejs3\helpers\esm\defineProperty.js:1
(function (exports, require, module, __filename, __dirname) { import _Object$defineProperty from "../../core-js/object/define-property";
^^^^^^
SyntaxError: Unexpected token import
at new Script (vm.js:51:7)
at NativeCompileCache._moduleCompile (C:\Users\marat.m\PhpstormProjects\b2b-node\node_modules\v8-compile-cache\v8-compile-cache.js:226:18)
at Module._compile (C:\Users\marat.m\PhpstormProjects\b2b-node\node_modules\v8-compile-cache\v8-compile-cache.js:172:36)
at Module._compile (C:\Users\marat.m\PhpstormProjects\b2b-node\node_modules\pirates\lib\index.js:99:24)
at Module._extensions..js (module.js:660:10)
at Object.newLoader [as .js] (C:\Users\marat.m\PhpstormProjects\b2b-node\node_modules\pirates\lib\index.js:104:7)
at Module.load (module.js:561:32)
at tryModuleLoad (module.js:501:12)
at Function.Module._load (module.js:493:3)
at Module.require (module.js:593:17)
at require (C:\Users\marat.m\PhpstormProjects\b2b-node\node_modules\v8-compile-cache\v8-compile-cache.js:159:20)
at Object.<anonymous> (C:\Users\marat.m\PhpstormProjects\b2b-node\webpack.config.babel.js:29:47)
at Module._compile (C:\Users\marat.m\PhpstormProjects\b2b-node\node_modules\v8-compile-cache\v8-compile-cache.js:178:30)
at Module._compile (C:\Users\marat.m\PhpstormProjects\b2b-node\node_modules\pirates\lib\index.js:99:24)
at Module._extensions..js (module.js:660:10)
at Object.newLoader [as .js] (C:\Users\marat.m\PhpstormProjects\b2b-node\node_modules\pirates\lib\index.js:104:7)
at Module.load (module.js:561:32)
at tryModuleLoad (module.js:501:12)
at Function.Module._load (module.js:493:3)
at Module.require (module.js:593:17)
at require (C:\Users\marat.m\PhpstormProjects\b2b-node\node_modules\v8-compile-cache\v8-compile-cache.js:159:20)
at WEBPACK_OPTIONS (C:\Users\marat.m\PhpstormProjects\b2b-node\node_modules\webpack-cli\bin\convert-argv.js:133:13)
at requireConfig (C:\Users\marat.m\PhpstormProjects\b2b-node\node_modules\webpack-cli\bin\convert-argv.js:135:6)
at C:\Users\marat.m\PhpstormProjects\b2b-node\node_modules\webpack-cli\bin\convert-argv.js:142:17
at Array.forEach (<anonymous>)
at module.exports (C:\Users\marat.m\PhpstormProjects\b2b-node\node_modules\webpack-cli\bin\convert-argv.js:140:15)
at yargs.parse (C:\Users\marat.m\PhpstormProjects\b2b-node\node_modules\webpack-cli\bin\cli.js:241:39)
at Object.parse (C:\Users\marat.m\PhpstormProjects\b2b-node\node_modules\webpack-cli\node_modules\yargs\yargs.js:563:18)
at C:\Users\marat.m\PhpstormProjects\b2b-node\node_modules\webpack-cli\bin\cli.js:219:8
at Object.<anonymous> (C:\Users\marat.m\PhpstormProjects\b2b-node\node_modules\webpack-cli\bin\cli.js:538:3)

protractor E/launcher - Error: ReferenceError: window is not defined

I had created an angular library with angular-cli v6 and ng-packagr that include ngx-bootstrap 3.0.1 as a peerDependency I have no problem running the app, but if I start protractor I get the folloing error:
I/launcher - Running 1 instances of WebDriver
I/direct - Using ChromeDriver directly...
DevTools listening on ws://127.0.0.1:12281/devtools/browser/e174b42c-8db0-494a-aba0-4366d555a98b
E/launcher - Error: ReferenceError: window is not defined
at Object. (\node_modules\ngx-bootstrap\bundles\webpack:ngx-bootstrap.umd\webpack\universalModuleDefinition:10:2)
at Module._compile (module.js:643:30)
at Object.Module._extensions..js (module.js:654:10)
at Module.load (module.js:556:32)
at tryModuleLoad (module.js:499:12)
at Function.Module._load (module.js:491:3)
at Module.require (module.js:587:17)
at require (internal/module.js:11:18)
at \dist\sg-ng-core-components\bundles\sg-ng-core-components.umd.js:2:268
at Object. (\dist\sg-ng-core-components\bundles\sg-ng-core-components.umd.js:5:2)
this is the tsconfig.lib.ts:
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "../../out-tsc/lib",
"target": "es2015",
"module": "es2015",
"moduleResolution": "node",
"declaration": true,
"sourceMap": true,
"inlineSources": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"importHelpers": true,
"types": [],
"lib": [
"dom",
"es2015"
]
},
"angularCompilerOptions": {
"annotateForClosureCompiler": true,
"skipTemplateCodegen": true,
"strictMetadataEmit": true,
"fullTemplateTypeCheck": true,
"strictInjectionParameters": true,
"flatModuleId": "AUTOGENERATED",
"flatModuleOutFile": "AUTOGENERATED"
},
"exclude": [
"src/test.ts",
"**/*.spec.ts"
]
}
and this is tsconfig.e2e:
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/e2e",
"module": "commonjs",
"target": "es2017",
"types": [
"jasmine",
"node"
]
}
}
It seems it is due to ngx-bootstrap.umd, but it work outside the e2e test. does anyone know if it is due to ng-packagr, protractor or ngx-bootstrap?
And may someone explain me how is it possible that protractor throws an error in the source code of a library (that it work with ng serve) ?
Thanks in advance

protractor + angular 6 library throw Error: ReferenceError: window is not defined

may I ask you why my app works with ng serve and ng build but if I run protractor, my e2e test fails with this message?
[16:35:07] I/launcher - Running 1 instances of WebDriver
[16:35:07] I/direct - Using ChromeDriver directly...
[16:35:13] E/launcher - Error: ReferenceError: window is not defined
at Object.<anonymous> (\node_modules\ngx-bootstrap\bundles\webpack:\ngx-bootstrap.umd\webpack\universalModuleDefinition:10:2)
at Module._compile (module.js:643:30)
at Object.Module._extensions..js (module.js:654:10)
at Module.load (module.js:556:32)
at tryModuleLoad (module.js:499:12)
at Function.Module._load (module.js:491:3)
at Module.require (module.js:587:17)
at require (internal/module.js:11:18)
at \dist\sg-ng-core-components\bundles\sg-ng-core-components.umd.js:2:268
at Object.<anonymous> (\dist\sg-ng-core-components\bundles\sg-ng-core-components.umd.js:5:2)
Following the tsconfig.e2e
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/e2e",
"module": "commonjs",
"target": "es2017",
"types": [
"jasmine",
"node"
]
}
}
And this is my tsconfig.app
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/app",
"module": "es2015",
"baseUrl": "",
"types": [
"node"
]
},
"exclude": [
"test.ts",
"**/*.spec.ts"
]
}