Can't import openai in Node - javascript

I have Node 16.13.1 installed and I installed openai globally with 'npm install -g openai'.
I imported the packages inside my script using:
const { Configuration, OpenAIApi } = require('openai')
However, when I ran my script, I got this error:
PS D:\Projects\OpenAI-Chat> node conversation.js
node:internal/modules/cjs/loader:936
throw err;
^
Error: Cannot find module 'openai'
Require stack:
- D:\Projects\OpenAI-Chat\conversation.js
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> (D:\Projects\OpenAI-Chat\conversation.js:1:38)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [ 'D:\\Projects\\OpenAI-Chat\\conversation.js' ]
}
How do I fix this?

You have to install it locally with
npm i openai
because Node.js doesn't search in the global folder for dependencies for the local project. Global installation is for global executables and its dependencies.

Related

Cannot find module 'discord.js', console reporting

I am very new using discord's javascript
This is also my first time posting on stackoverflow!
Anyway
Here's the full error
Error: Cannot find module 'discord.js'
Require stack:
- /home/runner/multiple-purpose-discord-bot-like-carlbot/xp.js
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> (/home/runner/multiple-purpose-discord-bot-like-carlbot/xp.js:1: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 Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [ '/home/runner/multiple-purpose-discord-bot-like-carlbot/xp.js' ]
}
To my limited knowledge, this is either i made a typo
OR some package is outdated, here's the full packages list
I also suspect that i incorrectly implemented the amethyste-api i am using, here's my code
It's in a config file, should've i put const mySecret = process.env['ame'] in the main file instead?, I do need it to be in the config for ease of access
npm install discord.js (manually through console/shell)
did do some stuff but stil didn't work
npm xp.js (manually through console/shell)
this is what i am supposed to run on start manually, that what gives the error
You could run the following commands one after the other:
`npm init`
and then
`npm i discord.js`

gatsby is not working after installing windows 10 and latest NodeJS

I have created gatsby project as instructed in official website of gatsbyjs but it's not working.
NodeJS version: v16.15.0,
npm version: 8.8.0,
gatsby version: 4.13.0,
gatsby CLI version: 4.13.0
C:\Users\Dell\Desktop\New folder\my-app>npm run develop
> gatsby-starter-default#0.1.0 develop
> gatsby develop
C:\Users\Dell\Desktop\New folder\my-app\node_modules\yoga-layout-prebuilt\yoga-layout\build\Release\nbind.js:53
throw ex;
^
Error: The specified module could not be found.
\\?\C:\Users\Dell\Desktop\New folder\my-app\node_modules\#parcel\source-map\parcel_sourcemap_node\artifacts\index.win32-x64-msvc.node
at Object.Module._extensions..node (node:internal/modules/cjs/loader:1189:18)
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)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (C:\Users\Dell\Desktop\New folder\my-app\node_modules\#parcel\source-map\parcel_sourcemap_node\index.js:15:18)
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)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (C:\Users\Dell\Desktop\New folder\my-app\node_modules\#parcel\source-map\dist\node.js:14:18)
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) {
code: 'ERR_DLOPEN_FAILED'
}
Try removing your package-lock.json, your node_modules and run the npm install again.
If the issue persist try:
Bumping your gatsby-cli version
Downgrading your Node version (since you are in the latest LTS)
Switching to yarn
Related resources/workarounds:
https://github.com/gatsbyjs/gatsby/issues/23378
https://lifesaver.codes/answer/cli-yoga-layout-prebuilt-error-on-gatsby-build-24577
https://github.com/gatsbyjs/gatsby/issues/24577

Error: Cannot find module 'react-dev-utils/typescriptFormatter'

I buy a react theme from theme forest and trying to open it I install npm and then I execute the command npm start and I get the error showing bellow. I send a message to developer he reply back and said execute the command npm install react-dev-utils --save
I try this but still getting the same error.
So can anyone help me to resolve this problem.
PS C:\Theme\reactjs\Template> npm start
> Artha#0.1.0 start
> node scripts/start.js
node:internal/modules/cjs/loader:936
throw err;
^
**Error: Cannot find module 'react-dev-utils/WatchMissingNodeModulesPlugin'**
Require stack:
- C:\Theme\reactjs\Template\config\webpack.config.js
- C:\Theme\reactjs\Template\scripts\start.js
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> (C:\Theme\reactjs\Template\config\webpack.config.js:16:39)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153: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: [
'C:\\Theme\\reactjs\\Template\\config\\webpack.config.js',
'C:\\Theme\\reactjs\\Template\\scripts\\start.js'
]
}
Sometime I am getting this error
PS C:\Theme\reactjs\Template> npm start
> Artha#0.1.0 start
> node scripts/start.js
node:internal/modules/cjs/loader:936
throw err;
^
**Error: Cannot find module 'react-dev-utils/typescriptFormatter'**
Require stack:
- C:\Theme\reactjs\Template\config\webpack.config.js
- C:\Theme\reactjs\Template\scripts\start.js
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> (C:\Theme\reactjs\Template\config\webpack.config.js:23:29)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153: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: [
'C:\\Theme\\reactjs\\Template\\config\\webpack.config.js',
'C:\\Theme\\reactjs\\Template\\scripts\\start.js'
]
}

VUE Error: Cannot find module 'lru-cache'

Good morning, first I would like to apologize for my English.
I am having a problem when creating a project to follow, I am taking the following steps.
STEP 1: npm install #vue/cli
STEP 2: vue create myproject
In the second step, I have the following error.
PS C:\Users\Bruno\Desktop\vue\VUE-CLI> vue create myproject
internal/modules/cjs/loader.js:883
throw err;
^
Error: Cannot find module 'lru-cache'
Require stack:
- C:\Users\Bruno\AppData\Roaming\npm\node_modules\#vue\cli\node_modules\#vue\cli-shared-utils\lib\env.js
- C:\Users\Bruno\AppData\Roaming\npm\node_modules\#vue\cli\node_modules\#vue\cli-shared-utils\index.js
- C:\Users\Bruno\AppData\Roaming\npm\node_modules\#vue\cli\bin\vue.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\Bruno\AppData\Roaming\npm\node_modules\#vue\cli\node_modules\#vue\cli-shared-utils\lib\env.js:4:13)
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 Module.require (internal/modules/cjs/loader.js:952:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'C:\\Users\\Bruno\\AppData\\Roaming\\npm\\node_modules\\#vue\\cli\\node_modules\\#vue\\cli-shared-utils\\lib\\env.js',
'C:\\Users\\Bruno\\AppData\\Roaming\\npm\\node_modules\\#vue\\cli\\node_modules\\#vue\\cli-shared-utils\\index.js',
'C:\\Users\\Bruno\\AppData\\Roaming\\npm\\node_modules\\#vue\\cli\\bin\\vue.js'
]
}
PS C:\Users\Bruno\Desktop\vue\VUE-CLI>
Try using npx maybe? Ensuring you have the latest updates
npx #vue/cli create my-project
Is the folder you intend to install the project into Vue/vue-cli? Don't know if anything n there is affecting it

node.js and node-postgres syntax error

I just installed node-postgres by running npm install pg .
In my source code, I added var pg = require('pg");
and when I run I now get
module.js:340
throw err;
^
Error: Cannot find module 'pg'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/Users/rrazavipour-lp/Documents/workspace/Astute/app.js:9:10)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.runMain [as _onTimeout] (module.js:497:10)
What step am I missing?
Where is the node_modules folder in relation to your application?
from http://nodejs.org/api/modules.html:
If the module identifier passed to require() is not a native module, and does not begin with '/', '../', or './', then node starts at the parent directory of the current module, and adds /node_modules, and attempts to load the module from that location.

Categories

Resources