使用brain.js在Node.js服务器中,但出现错误gpu.js不可用。

huangapple go评论82阅读模式
英文:

Using brain.js in nodejs server but getting error gpu.js not present

问题

我使用brain.js库创建神经网络。
包已经安装完毕,但当我运行服务器时,我收到了以下错误消息。

找不到模块gpu.js

然后我安装了"npm i gpu.js"
然后我得到了以下错误 - 以下错误消息说要安装Visual Studio 2022的最新版本并在其中运行。我尝试了,但没有成功。

npm WARN deprecated uuid@3.4.0: 请升级到版本7或更高版本。较旧的版本可能在某些情况下使用Math.random(),这是有问题的。请参阅https://v8.dev/blog/math-random了解详细信息。
npm WARN deprecated request@2.88.2: request已弃用,请参阅https://github.com/request/request/issues/3142
npm ERR! code 1
npm ERR! path C:\Users\priya\JSAIML\ytHelper\node_modules\gl
npm ERR! command failed
npm ERR! command C:\Windows\system32\cmd.exe /d /s /c prebuild-install || node-gyp rebuild
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using node-gyp@7.1.2
npm ERR! gyp info using node@18.8.0 | win32 | x64
npm ERR! gyp info find Python using Python version 3.10.3 found at "C:\Users\priya\AppData\Local\Programs\Python\Python310\python.exe"
npm ERR! gyp ERR! find VS
npm ERR! gyp ERR! find VS msvs_version not set from command line or npm config
npm ERR! gyp ERR! find VS VCINSTALLDIR not set, not running in VS Command Prompt
npm ERR! gyp ERR! find VS could not use PowerShell to find Visual Studio 2017 or newer, try re-running with '--loglevel silly' for more details
npm ERR! gyp ERR! find VS looking for Visual Studio 2015
npm ERR! gyp ERR! find VS - not found
npm ERR! gyp ERR! find VS not looking for VS2013 as it is only supported up to Node.js 8
npm ERR! gyp ERR! find VS
npm ERR! gyp ERR! find VS **************************************************************
npm ERR! gyp ERR! find VS 您需要安装Visual Studio的最新版本,包括"C++桌面开发"工作负载。
npm ERR! gyp ERR! find VS 要了解更多信息,请参阅文档:
npm ERR! gyp ERR! find VS https://github.com/nodejs/node-gyp#on-windows
npm ERR! gyp ERR! find VS **************************************************************
npm ERR! gyp ERR! find VS
npm ERR! gyp ERR! configure error
npm ERR! gyp ERR! stack Error: Could not find any Visual Studio installation to use
npm ERR! gyp ERR! stack     at VisualStudioFinder.fail (C:\Users\priya\JSAIML\ytHelper\node_modules\node-gyp\lib\find-visualstudio.js:121:47)
npm ERR! gyp ERR! stack     at C:\Users\priya\JSAIML\ytHelper\node_modules\node-gyp\lib\find-visualstudio.js:74:16
npm ERR! gyp ERR! stack     at VisualStudioFinder.findVisualStudio2013 (C:\Users\priya\JSAIML\ytHelper\node_modules\node-gyp\lib\find-visualstudio.js:351:14)
npm ERR! gyp ERR! stack     at C:\Users\priya\JSAIML\ytHelper\node_modules\node-gyp\lib\find-visualstudio.js:70:14
npm ERR! gyp ERR! stack     at C:\Users\priya\JSAIML\ytHelper\node_modules\node-gyp\lib\find-visualstudio.js:372:16
npm ERR! gyp ERR! stack     at C:\Users\priya\JSAIML\ytHelper\node_modules\node-gyp\lib\util.js:54:7 
npm ERR! gyp ERR! stack     at C:\Users\priya\JSAIML\ytHelper\node_modules\node-gyp\lib\util.js:33:16npm ERR! gyp ERR! stack     at ChildProcess.exithandler (node:child_process:420:5)
npm ERR! gyp ERR! stack     at ChildProcess.emit (node:events:513:28)
npm ERR! gyp ERR! stack     at maybeClose (node:internal/child_process:1091:16)
npm ERR! gyp ERR! System Windows_NT 10.0.22000
npm ERR! gyp ERR! command "C:\Users\priya\.nvm\versions\node\v18.8.0\bin\node.exe" "C:\Users\priya\JSAIML\ytHelper\node_modules\node-gyp\bin\node-gyp.js" "rebuild"
npm ERR! gyp ERR! cwd C:\Users\priya\JSAIML\ytHelper\node_modules\gl
npm ERR! gyp ERR! node -v v18.8.0
npm ERR! gyp ERR! node-gyp -v v7.1.2
npm ERR! gyp ERR! not ok

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\priya\AppData\Local\npm-cache\_logs23-01-08T17_34_38_565Z-debug-0.log```

这是我的代码的样子

```javascript
import express from 'express';
import * as brain from 'brain.js/dist/index.js';
import dotenv from 'dotenv';
import ytData from './md/data.js';

dotenv.config();
const app = express();
const PORT = process.env.PORT || 8000;

const network = new brain.recurrent.LSTM();

const trainingData = ytData.map((item, i) => ({
  input: item.title,
  output: item.views,
}));

network.train(trainingData, { iterations: 2000 });

const outputData = network.run("Simple Machine Learning With JavaScript - Brain.js");

app.get('/', (req, res) => {
  // res.json({message : `On this title you will probably get around ${outputData} views`})
  res.send("hello");
});

app.listen(PORT, () => {
  console.log(`Running up the hill at ${PORT}km/hr`);
});

任何帮助都将不胜感激。

英文:

I'm using brain.js library for creating Nural network.
Package installed perfectly, but when I ran the server then I get this error.

Cannot find module gpu.js

Then I installed "npm i gpu.js"
Then I got this error - This below error says that install visual studio 2022 latest version and run this in that. I did but didnt worked.

code part

npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm ERR! code 1
npm ERR! path C:\Users\priya\JSAIML\ytHelper\node_modules\gl
npm ERR! command failed
npm ERR! command C:\Windows\system32\cmd.exe /d /s /c prebuild-install || node-gyp rebuild
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using node-gyp@7.1.2
npm ERR! gyp info using node@18.8.0 | win32 | x64
npm ERR! gyp info find Python using Python version 3.10.3 found at "C:\Users\priya\AppData\Local\Programs\Python\Python310\python.exe"
npm ERR! gyp ERR! find VS
npm ERR! gyp ERR! find VS msvs_version not set from command line or npm config
npm ERR! gyp ERR! find VS VCINSTALLDIR not set, not running in VS Command Prompt
npm ERR! gyp ERR! find VS could not use PowerShell to find Visual Studio 2017 or newer, try re-running with '--loglevel silly' for more details
npm ERR! gyp ERR! find VS looking for Visual Studio 2015
npm ERR! gyp ERR! find VS - not found
npm ERR! gyp ERR! find VS not looking for VS2013 as it is only supported up to Node.js 8
npm ERR! gyp ERR! find VS
npm ERR! gyp ERR! find VS **************************************************************
npm ERR! gyp ERR! find VS You need to install the latest version of Visual Studio
npm ERR! gyp ERR! find VS including the "Desktop development with C++" workload.
npm ERR! gyp ERR! find VS For more information consult the documentation at:
npm ERR! gyp ERR! find VS https://github.com/nodejs/node-gyp#on-windows
npm ERR! gyp ERR! find VS **************************************************************
npm ERR! gyp ERR! find VS
npm ERR! gyp ERR! configure error
npm ERR! gyp ERR! stack Error: Could not find any Visual Studio installation to use
npm ERR! gyp ERR! stack     at VisualStudioFinder.fail (C:\Users\priya\JSAIML\ytHelper\node_modules\node-gyp\lib\find-visualstudio.js:121:47)
npm ERR! gyp ERR! stack     at C:\Users\priya\JSAIML\ytHelper\node_modules\node-gyp\lib\find-visualstudio.js:74:16
npm ERR! gyp ERR! stack     at VisualStudioFinder.findVisualStudio2013 (C:\Users\priya\JSAIML\ytHelper\node_modules\node-gyp\lib\find-visualstudio.js:351:14)
npm ERR! gyp ERR! stack     at C:\Users\priya\JSAIML\ytHelper\node_modules\node-gyp\lib\find-visualstudio.js:70:14
npm ERR! gyp ERR! stack     at C:\Users\priya\JSAIML\ytHelper\node_modules\node-gyp\lib\find-visualstudio.js:372:16
npm ERR! gyp ERR! stack     at C:\Users\priya\JSAIML\ytHelper\node_modules\node-gyp\lib\util.js:54:7 
npm ERR! gyp ERR! stack     at C:\Users\priya\JSAIML\ytHelper\node_modules\node-gyp\lib\util.js:33:16npm ERR! gyp ERR! stack     at ChildProcess.exithandler (node:child_process:420:5)
npm ERR! gyp ERR! stack     at ChildProcess.emit (node:events:513:28)
npm ERR! gyp ERR! stack     at maybeClose (node:internal/child_process:1091:16)
npm ERR! gyp ERR! System Windows_NT 10.0.22000
npm ERR! gyp ERR! command "C:\\Users\\priya\\.nvm\\versions\\node\\v18.8.0\\bin\\node.exe" "C:\\Users\\priya\\JSAIML\\ytHelper\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
npm ERR! gyp ERR! cwd C:\Users\priya\JSAIML\ytHelper\node_modules\gl
npm ERR! gyp ERR! node -v v18.8.0
npm ERR! gyp ERR! node-gyp -v v7.1.2
npm ERR! gyp ERR! not ok

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\priya\AppData\Local\npm-cache\_logs23-01-08T17_34_38_565Z-debug-0.log```

this is how my code looks like 

code ->


import express from 'express';
import * as brain from 'brain.js/dist/index.js';
import dotenv from 'dotenv'
import  ytData  from './md/data.js';


dotenv.config()
const app = express()
const PORT = process.env.PORT || 8000


const network = new brain.recurrent.LSTM();

const trainingData = ytData.map((item,i)=>({
    input : item.title,
    output : item.views,
}))


network.train(trainingData,{iterations : 2000});

const outputData = network.run("Simple Machine Learning With JavaScript - Brain.js")


app.get('/',(req,res)=>{
    // res.json({message : `On this title you will probably get around ${outputData} views`})
    res.send("hello")
})



app.listen(PORT, ()=>{
    console.log(`Running up the hill at ${PORT}km/hr`)
})

**Any help will be appreciated.**

</details>


# 答案1
**得分**: 1

我经历过类似的问题。

为了解决它,我进行了以下操作:

1. 首先,我[使用了一个较旧版本的Node][1],以解决`“npm ERR! code 1”`错误。不确定这部分是否与您相关,但我需要它:
   - 安装了`nvm`,然后运行:
   - `nvm install v15.14.0`
   - `nvm use v15.14.0`
2. 然后,我安装了一个较旧版本的`brain.js`,以解决`Cannot find module 'gpu.js'`错误:
   - 更新了`package.json`,使用了一个较旧版本:`"brain.js": "^1.6.1"`
   - 重新安装:`npm install brain.js`
   - 再次运行应用程序:`node index.js`

好的 - 希望这对您有帮助 :)

[1]: https://stackoverflow.com/a/67487338/906192
[2]: https://www.freecodecamp.org/news/node-version-manager-nvm-install-guide/

<details>
<summary>英文:</summary>

I experienced similar pain.

To resolve it, I did the following:

 1. First, I [used an older version of node][1], to resolve an `“npm ERR!
    code 1”` error. Not sure if this part is relevant for you, but I needed it:
       - [Installed][2] `nvm`, and then ran:
       - `nvm install v15.14.0`
       - `nvm use v15.14.0`
 2. Then, I installed an older version of `brain.js`, to resolve the `Cannot find module &#39;gpu.js&#39;` error:
       - Updated `package.json` with an older version: `&quot;brain.js&quot;: &quot;^1.6.1&quot;`
       - Re-installed: `npm install brain.js`
       - Ran the app again: `node index.js`

OK - hope that&#39;s helpful :)
 


  [1]: https://stackoverflow.com/a/67487338/906192
  [2]: https://www.freecodecamp.org/news/node-version-manager-nvm-install-guide/

</details>



huangapple
  • 本文由 发表于 2023年1月9日 03:47:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/75050784.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定