Why am I getting error "requires a generator function" - javascript

I installed the module "koa-cache-control" via npm.
I added the following lines to my index.js.
const cacheControl = require('koa-cache-control');
Then...
app.use(cacheControl({
noCache: true
}));
Here is the error I get when starting node.
Any clues?
AssertionError: app.use() requires a generator function
at Application.app.use
(/home/www/node_modules/koa/lib/application.js:106:5)
at Object.<anonymous> (/home/www/index.js:17:5)
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)
at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:389:7)
at startup (bootstrap_node.js:149:9)
Thanks!

You seem to be using an old version of Koa. The 1.x versions used a generator-based type of middleware, which was changed to Promises in version 2.
You'll either have to update Koa or use the old version 1.0.0 of koa-cache-control.

Related

Basic Node Commands Not Working After Updating NodeJS

I've attempted to update my node version by deleting nodejs file from ProgramFilesx86 folder and using the windows installer to install the latest file. When I go to try and initialize a node project or npx create-react-app it gives me the following:
TypeError: Class extends value undefined is not a constructor or null
at Object.<anonymous> (C:\Users\Mickell\AppData\Roaming\nvm\v13.8.0\node_modules\npm\node_modules\socks-proxy-agent\dist\agent.js:114:44)
at Module._compile (node:internal/modules/cjs/loader:1097:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1151:10)
at Module.load (node:internal/modules/cjs/loader:975:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:999:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (C:\Users\Mickell\AppData\Roaming\nvm\v13.8.0\node_modules\npm\node_modules\socks-proxy-agent\dist\index.js:5:33)
at Module._compile (node:internal/modules/cjs/loader:1097:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1151:10)
at Module.load (node:internal/modules/cjs/loader:975:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:999:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (C:\Users\Mickell\AppData\Roaming\nvm\v13.8.0\node_modules\npm\node_modules\make-fetch-happen\lib\agent.js:169:25)
at Module._compile (node:internal/modules/cjs/loader:1097:14)
Could not determine Node.js install directory
What am I doing wrong?
This happens when you run a newer version of npm with an older version of node. Make sure no old version of node is in your path.

TypeError when trying to run npm init in blank folder

I am trying to get into Discord bot making, and I have node installed, version 17.3.0.
When I try to run npm init in a blank folder on my desktop, it throws me this error:
TypeError: Class extends value undefined is not a constructor or null
at Object.<anonymous> (C:\Users\bluep\AppData\Roaming\nvm\v14.15.4\node_modules\npm\node_modules\socks-proxy-agent\dist\agent.js:114:44)
at Module._compile (node:internal/modules/cjs/loader:1097:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1149:10)
at Module.load (node:internal/modules/cjs/loader:975:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:999:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (C:\Users\bluep\AppData\Roaming\nvm\v14.15.4\node_modules\npm\node_modules\socks-proxy-agent\dist\index.js:5:33)
at Module._compile (node:internal/modules/cjs/loader:1097:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1149:10)
at Module.load (node:internal/modules/cjs/loader:975:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:999:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (C:\Users\bluep\AppData\Roaming\nvm\v14.15.4\node_modules\npm\node_modules\make-fetch-happen\lib\agent.js:161:25)
at Module._compile (node:internal/modules/cjs/loader:1097:14)
TypeError: Class extends value undefined is not a constructor or null
at Object.<anonymous> (C:\Users\bluep\AppData\Roaming\nvm\v14.15.4\node_modules\npm\node_modules\socks-proxy-agent\dist\agent.js:114:44)
at Module._compile (node:internal/modules/cjs/loader:1097:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1149:10)
at Module.load (node:internal/modules/cjs/loader:975:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:999:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (C:\Users\bluep\AppData\Roaming\nvm\v14.15.4\node_modules\npm\node_modules\socks-proxy-agent\dist\index.js:5:33)
at Module._compile (node:internal/modules/cjs/loader:1097:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1149:10)
at Module.load (node:internal/modules/cjs/loader:975:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:999:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (C:\Users\bluep\AppData\Roaming\nvm\v14.15.4\node_modules\npm\node_modules\make-fetch-happen\lib\agent.js:161:25)
at Module._compile (node:internal/modules/cjs/loader:1097:14)
It will throw me this error when I try to run any npm command. I have never seen any error like this before in this situation, and I haven't found any other person via google that's encountered this situation.
Any help is appreciated. I could be (probably am) overlooking something extremely simple and overthinking the f out of this.
Update:
The issue ended up being there was an old install of Node on my computer that did not properly uninstall when I tried to uninstall it. This caused all my issues. Thank you to everyone who tried to help, problem solved.
If anyone comes across this issue, the old version will be located in your nvm folder within your AppData directory.
That's a weird one. I would suggest using Node 16.13.1 LTS instead. LTS means Long Term Support. This means that it is probably more stable than that Node calls the "current" version. Also, since you are using Windows, try the installers available on Node.js' homepage instead of nvm. I've had issues with nvm in the past, though I've never tried it on Windows.

Cannot run Javascript code on Atom editor

Atom is not able to run javascript code for some reason, I have tried both packages such as atom runner and atom script with no success.
I have Node JS installed on my computer and javascript package installed on Atom, I have no idea why it does not work.
Here is the code which is returned after trying to run a javascript prompt.
C:\Users\artisan\Desktop\hi.js:1
(function (exports, require, module, __filename, __dirname) { var hi = prompt("wt");
^
ReferenceError: prompt is not defined
at Object.<anonymous> (C:\Users\artisan\Desktop\hi.js:1:72)
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)
at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:394:7)
at startup (bootstrap_node.js:149:9)
at bootstrap_node.js:509:3
prompt() is a function which is implemented by Web Browsers.
In serversided JS you can't use this function.

Error: Cannot find module '../build/Release/bson' on Mac

I am using node.js to run one app given by my professor on my chrome. Something wrong happen, but I don't know because I am a rookie.
The structure is as follows:
/app
/models
answers.js
questions.js
sessions.js
user.js
passport.js
qmanage.js
routes.js
/config
auth.js
database.js
mcd.js
package.json
/public
some css png fonts jpg document
qloader.js
server.js
/views
some ejs document
At first, it shows this problem:
module.js:457
throw err;
^
Error: Cannot find module 'mongoose'
at Function.Module._resolveFilename (module.js:455:15)
at Function.Module._load (module.js:403:25)
at Module.require (module.js:483:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/Users/shen/Desktop/os/cse303.p2/server.js:2:16)
at Module._compile (module.js:556:32)
at Object.Module._extensions..js (module.js:565:10)
at Module.load (module.js:473:32)
at tryModuleLoad (module.js:432:12)
at Function.Module._load (module.js:424:3)
then, based on this help Node.js error Error: Cannot find module 'mongoose' I run npm install mongoose in my root path of project. Then I have those error below:
dyn143030:cse shen$ node server.js
{ Error: Cannot find module '../build/Release/bson'
at Function.Module._resolveFilename (module.js:455:15)
at Function.Module._load (module.js:403:25)
at Module.require (module.js:483:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/Users/shen/Desktop/os/cse303.p2/node_modules/bson/ext/index.js:15:10)
at Module._compile (module.js:556:32)
at Object.Module._extensions..js (module.js:565:10)
at Module.load (module.js:473:32)
at tryModuleLoad (module.js:432:12)
at Function.Module._load (module.js:424:3) code: 'MODULE_NOT_FOUND' }
js-bson: Failed to load c++ bson extension, using pure JS version
events.js:160
throw er; // Unhandled 'error' event
^
Error: Invalid mongodb uri. Missing hostname
at muri (/Users/shen/Desktop/os/cse303.p2/node_modules/muri/lib/index.js:40:11)
at NativeConnection.Connection.open (/Users/shen/Desktop/os/cse303.p2/node_modules/mongoose/lib/connection.js:195:16)
at Mongoose.connect (/Users/shen/Desktop/os/cse303.p2/node_modules/mongoose/lib/index.js:212:15)
at Object.<anonymous> (/Users/shen/Desktop/os/cse303.p2/server.js:4:10)
at Module._compile (module.js:556:32)
at Object.Module._extensions..js (module.js:565:10)
at Module.load (module.js:473:32)
at tryModuleLoad (module.js:432:12)
at Function.Module._load (module.js:424:3)
at Module.runMain (module.js:590:10)
at run (bootstrap_node.js:394:7)
at startup (bootstrap_node.js:149:9)
at bootstrap_node.js:509:3
I tried to find solution from this help
Cannot find module '../build/Release/bson'] code: 'MODULE_NOT_FOUND' } js-bson: Failed to load c++ bson extension, using pure JS version
but it seems not my case, because I am using OS X 10.11.3
dyn143030:cse shen$ node -v
v6.5.0
dyn143030:cse shen$ npm -v
3.10.3
From my aspect, I think the system find bson someplace wrong, so how to modify it? Thanks! If any more information is need, please tell me.
I find in node_modules\bson\ext\index.js
and change path on 10th line
bson = require('../build/Release/bson'); to bson = require('bson');
You can try adding mongoose to the dependency list in the package.json file, or also doing >npm install mongoose in the project folder.

TypeError: undefined is not a function when clone old node modules

I tried to run a node app that I've cloned from
https://github.com/jensoleg/mongoose-timeseries
So I just cloned it and npm install and dependencies but when I ran an example file it gives this error! I've looked at the core code but I don't know what is the problem exactly.
mti.init('test', {interval: 1}); //second: Boolean, minute: Boolean
^
TypeError: undefined is not a function
at Object.<anonymous> (/Users/Kanin/Desktop/test/test.js:7:5)
at Module._compile (module.js:460:26)
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 Function.Module.runMain (module.js:501:10)
at startup (node.js:129:16)
at node.js:814:3

Categories

Resources