在 Visual Studio 代码中安装 brain.js 时出错

Error installing brain.js in Visual Studio Code

这里是新手。我最近切换到 Visual Studio 代码以与 Brain.js 一起使用,但是当我将它安装到终端(使用 NPM)时,出现错误。我尝试了多种其他解决方案,但 none 有效。任何帮助,将不胜感激。提前致谢=>

由于我也是 Linux 的新手,我尝试了一些安装命令的变体(如 sudo)并尝试在默认 Linux 终端上完成 Brain.js 安装但是无济于事 :( 。还有一件奇怪的事是我能够下载 BrainJS(较旧的库。)但不能 Brain.js

尽管我认为代码没有任何问题,但还是给了它。

const brain = require("brainjs");
let net = new brain.NeuralNetwork({ hiddenLayers: [3] });   // 
Setting up neural network

const restaurants = {                     // Dataset
  "KFC":"Monday",
  "Item no.1":"Tuesday",
  "Vaango":"Wednesday",
  "Taco Bell":"Thursday",
  "carls Jr.":"Friday",
  "":"Saturday",
  "Burger King":"Sunday"
}

const TrainingData = [];

for (let restaurantName in restaurants) {
    const dayOfWeek = restaurants[restaurantName];
    TrainingData.push({
      input: { [dayOfWeek]: 1 },
      output: { [restaurantName]: 1 }
});
}


const stats = net.train(TrainingData);

这是我收到的错误消息:

    npm ERR! Linux 5.0.0-23-generic
    npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "install" "brain.js"
    npm ERR! node v8.10.0
    npm ERR! npm  v3.5.2
    npm ERR! code EMISSINGARG

    npm ERR! typeerror Error: Missing required argument #1
    npm ERR! typeerror     at andLogAndFinish (/usr/share/npm/lib/fetch- 
    package-metadata.js:31:3)
    npm ERR! typeerror     at fetchPackageMetadata 
    (/usr/share/npm/lib/fetch-package-metadata.js:51:22)
    npm ERR! typeerror     at resolveWithNewModule 
    (/usr/share/npm/lib/install/deps.js:456:12)
    npm ERR! typeerror     at /usr/share/npm/lib/install/deps.js:190:5
    npm ERR! typeerror     at 
    /usr/share/npm/node_modules/slide/lib/async-map.js:52:35
    npm ERR! typeerror     at Array.forEach (<anonymous>)
    npm ERR! typeerror     at 
    /usr/share/npm/node_modules/slide/lib/async-map.js:52:11
    npm ERR! typeerror     at Array.forEach (<anonymous>)
    npm ERR! typeerror     at asyncMap 

(/usr/share/npm/node_modules/slide/lib/async-map.js:51:8)
npm ERR! typeerror     at exports.loadRequestedDeps (/usr/share/npm/lib/install/deps.js:188:3)
npm ERR! typeerror This is an error with npm itself. Please report this error at:
npm ERR! typeerror     <http://github.com/npm/npm/issues>

npm ERR! Please include the following file with any support request:
npm ERR!     /home/neel/Documents/VS-Code_Projects/npm-debug.log

和调试日志:--

0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'install', 'brain.js' ]
2 info using npm@3.5.2
3 info using node@v8.10.0
4 verbose config Skipping project config: /home/neel/.npmrc. (matches userconfig)
5 silly loadCurrentTree Starting
6 silly install loadCurrentTree
7 silly install readLocalPackageData
8 silly fetchPackageMetaData brain.js
9 silly fetchNamedPackageData brain.js
10 silly mapToRegistry name brain.js
11 silly mapToRegistry using default registry
12 silly mapToRegistry registry https://registry.npmjs.org/
13 silly mapToRegistry uri https://registry.npmjs.org/brain.js
14 verbose request uri https://registry.npmjs.org/brain.js
15 verbose request no auth needed
16 info attempt registry request try #1 at 21:59:12
17 verbose request id 74a22560d1b7c23a
18 verbose etag W/"9fb16e14a6b8c1d1ef1c110acba9db6b"
19 verbose lastModified Fri, 09 Aug 2019 11:09:50 GMT
20 http request GET https://registry.npmjs.org/brain.js
21 http 304 https://registry.npmjs.org/brain.js
22 verbose headers { date: 'Tue, 13 Aug 2019 16:29:14 GMT',
22 verbose headers   connection: 'keep-alive',
22 verbose headers   'set-cookie':
22 verbose headers    [ '__cfduid=d4bf1b2abca3b24131a1907349098099d1565713753; expires=Wed, 12-Aug-20 16:29:13 GMT; path=/; domain=.npmjs.org; HttpOnly' ],
22 verbose headers   'cf-cache-status': 'REVALIDATED',
22 verbose headers   'cache-control': 'max-age=300',
22 verbose headers   'cf-ray': '505c110c8bc58a5f-BOM',
22 verbose headers   etag: '"9fb16e14a6b8c1d1ef1c110acba9db6b"',
22 verbose headers   'expect-ct': 'max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"',
22 verbose headers   'last-modified': 'Fri, 09 Aug 2019 11:09:50 GMT',
22 verbose headers   vary: 'accept-encoding, accept',
22 verbose headers   'x-amz-meta-rev': '67-25f3ef5cf61222403c910fbd6b789aa9',
22 verbose headers   server: 'cloudflare' }
23 silly get cb [ 304,
23 silly get   { date: 'Tue, 13 Aug 2019 16:29:14 GMT',
23 silly get     connection: 'keep-alive',
23 silly get     'set-cookie':
23 silly get      [ '__cfduid=d4bf1b2abca3b24131a1907349098099d1565713753; expires=Wed, 12-Aug-20 16:29:13 GMT; path=/; domain=.npmjs.org; HttpOnly' ],
23 silly get     'cf-cache-status': 'REVALIDATED',
23 silly get     'cache-control': 'max-age=300',
23 silly get     'cf-ray': '505c110c8bc58a5f-BOM',
23 silly get     etag: '"9fb16e14a6b8c1d1ef1c110acba9db6b"',
23 silly get     'expect-ct': 'max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"',
23 silly get     'last-modified': 'Fri, 09 Aug 2019 11:09:50 GMT',
23 silly get     vary: 'accept-encoding, accept',
23 silly get     'x-amz-meta-rev': '67-25f3ef5cf61222403c910fbd6b789aa9',
23 silly get     server: 'cloudflare' } ]
24 verbose etag https://registry.npmjs.org/brain.js from cache
25 verbose get saving brain.js to /home/neel/.npm/registry.npmjs.org/brain.js/.cache.json
26 silly install normalizeTree
27 silly loadCurrentTree Finishing
28 silly loadIdealTree Starting
29 silly install loadIdealTree
30 silly cloneCurrentTree Starting
31 silly install cloneCurrentTreeToIdealTree
32 silly cloneCurrentTree Finishing
33 silly loadShrinkwrap Starting
34 silly install loadShrinkwrap
35 silly loadShrinkwrap Finishing
36 silly loadAllDepsIntoIdealTree Starting
37 silly install loadAllDepsIntoIdealTree
38 verbose stack Error: Missing required argument #1
38 verbose stack     at andLogAndFinish (/usr/share/npm/lib/fetch-package-metadata.js:31:3)
38 verbose stack     at fetchPackageMetadata (/usr/share/npm/lib/fetch-package-metadata.js:51:22)
38 verbose stack     at resolveWithNewModule (/usr/share/npm/lib/install/deps.js:456:12)
38 verbose stack     at /usr/share/npm/lib/install/deps.js:190:5
38 verbose stack     at /usr/share/npm/node_modules/slide/lib/async-map.js:52:35
38 verbose stack     at Array.forEach (<anonymous>)
38 verbose stack     at /usr/share/npm/node_modules/slide/lib/async-map.js:52:11
38 verbose stack     at Array.forEach (<anonymous>)
38 verbose stack     at asyncMap (/usr/share/npm/node_modules/slide/lib/async-map.js:51:8)
38 verbose stack     at exports.loadRequestedDeps (/usr/share/npm/lib/install/deps.js:188:3)
39 verbose cwd /home/neel/Documents/VS-Code_Projects
40 error Linux 5.0.0-23-generic
41 error argv "/usr/bin/node" "/usr/bin/npm" "install" "brain.js"
42 error node v8.10.0
43 error npm  v3.5.2
44 error code EMISSINGARG
45 error typeerror Error: Missing required argument #1
45 error typeerror     at andLogAndFinish (/usr/share/npm/lib/fetch-package-metadata.js:31:3)
45 error typeerror     at fetchPackageMetadata (/usr/share/npm/lib/fetch-package-metadata.js:51:22)
45 error typeerror     at resolveWithNewModule (/usr/share/npm/lib/install/deps.js:456:12)
45 error typeerror     at /usr/share/npm/lib/install/deps.js:190:5
45 error typeerror     at /usr/share/npm/node_modules/slide/lib/async-map.js:52:35
45 error typeerror     at Array.forEach (<anonymous>)
45 error typeerror     at /usr/share/npm/node_modules/slide/lib/async-map.js:52:11
45 error typeerror     at Array.forEach (<anonymous>)
45 error typeerror     at asyncMap (/usr/share/npm/node_modules/slide/lib/async-map.js:51:8)
45 error typeerror     at exports.loadRequestedDeps (/usr/share/npm/lib/install/deps.js:188:3)
46 error typeerror This is an error with npm itself. Please report this error at:
46 error typeerror     <http://github.com/npm/npm/issues>
47 verbose exit [ 1, true ]

npm ERR! npm  v3.5.2

如评论中所述,这是旧版本的 NPM,解决方案是更新到较新的版本。

您说:

Error installing brain.js

但是当你去安装require的时候,你使用的是"brainjs",而不是"brain.js":

const brain = require("brainjs");

您引用了两个不同的库,尽管有一个字符不同。使用这个:

const brain = require('brain.js');