简体   繁体   English

无法将 Brain.JS 导入我的 NodeJS 脚本

[英]Can't import Brain.JS into my NodeJS script

I'm trying to write a neural network using brain.js.我正在尝试使用 Brain.js 编写一个神经网络。 However, NodeJS doesn't allow me to do that neither with require('brain.js') nor with import 'brain.js' .但是,NodeJS 不允许我使用require('brain.js')import 'brain.js' Here is my code:这是我的代码:

const brain = require('brain.js')

const config = {
    iterations: 15000,
    log: true,
    logPeriod: 500,
    layers: [10]
}

const net = new brain.recurrent.LSTM()

const conjunctions = {
    0: 'Именительный',
    1: 'Родительный',
    2: 'Дательный',
    3: 'Винительный',
    4: 'Творительный',
    5: 'Предложный'
}

const inputData = [
    // some data for training
]

const test = 'Дельфина'

net.train(inputData)
const output = net.run(test)
console.log(`${conjunctions[output]} падеж`)

However, it shows me next error when running with require('brain.js') :但是,它在使用require('brain.js')运行时显示了下一个错误:

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module:         c:\Coding\Labs\Node.JS\MochaTest\node_modules\brain.js\src\index.js
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1156:13)
    at Module.load (internal/modules/cjs/loader.js:976:32)
    at Function.Module._load (internal/modules/cjs/loader.js:884:14)
    at Module.require (internal/modules/cjs/loader.js:1016:19)
    at require (internal/modules/cjs/helpers.js:69:18)
    at Object.<anonymous> (c:\Coding\Labs\Node.JS\MochaTest\index.js:1:15)
    at Module._compile (internal/modules/cjs/loader.js:1121:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1160:10)
    at Module.load (internal/modules/cjs/loader.js:976:32)
    at Function.Module._load (internal/modules/cjs/loader.js:884:14) {
      code: 'ERR_REQUIRE_ESM'

} }

And next error when running with import * as brain from 'brain.js' :使用import * as brain from 'brain.js'运行时出现下一个错误:

(node:2648) ExperimentalWarning: The ESM module loader is experimental.
file:///c:/Coding/Labs/Node.JS/MochaTest/node_modules/brain.js/src/index.js:1
const activation = require('./activation');
                   ^

ReferenceError: require is not defined
    at file:///c:/Coding/Labs/Node.JS/MochaTest/node_modules/brain.js/src/index.js:1:20
    at ModuleJob.run (internal/modules/esm/module_job.js:109:37)
    at async Loader.import (internal/modules/esm/loader.js:133:24)

What should I do and how to import it right when using NodeJS 13.2.0?使用 NodeJS 13.2.0 时我应该怎么做以及如何正确导入它? I have only brain.js and Mocha installed in this module.我在这个模块中只安装了 Brain.js 和 Mocha。

I'm trying to write a neural network using brain.js.我正在尝试使用brain.js编写神经网络。 However, NodeJS doesn't allow me to do that neither with require('brain.js') nor with import 'brain.js' .但是,NodeJS不允许我同时使用require('brain.js')import 'brain.js'来做到这import 'brain.js' Here is my code:这是我的代码:

const brain = require('brain.js')

const config = {
    iterations: 15000,
    log: true,
    logPeriod: 500,
    layers: [10]
}

const net = new brain.recurrent.LSTM()

const conjunctions = {
    0: 'Именительный',
    1: 'Родительный',
    2: 'Дательный',
    3: 'Винительный',
    4: 'Творительный',
    5: 'Предложный'
}

const inputData = [
    // some data for training
]

const test = 'Дельфина'

net.train(inputData)
const output = net.run(test)
console.log(`${conjunctions[output]} падеж`)

However, it shows me next error when running with require('brain.js') :但是,它显示了使用require('brain.js')运行时的下一个错误:

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module:         c:\Coding\Labs\Node.JS\MochaTest\node_modules\brain.js\src\index.js
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1156:13)
    at Module.load (internal/modules/cjs/loader.js:976:32)
    at Function.Module._load (internal/modules/cjs/loader.js:884:14)
    at Module.require (internal/modules/cjs/loader.js:1016:19)
    at require (internal/modules/cjs/helpers.js:69:18)
    at Object.<anonymous> (c:\Coding\Labs\Node.JS\MochaTest\index.js:1:15)
    at Module._compile (internal/modules/cjs/loader.js:1121:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1160:10)
    at Module.load (internal/modules/cjs/loader.js:976:32)
    at Function.Module._load (internal/modules/cjs/loader.js:884:14) {
      code: 'ERR_REQUIRE_ESM'

} }

And next error when running with import * as brain from 'brain.js' :当使用import * as brain from 'brain.js'运行时,下一个错误import * as brain from 'brain.js'

(node:2648) ExperimentalWarning: The ESM module loader is experimental.
file:///c:/Coding/Labs/Node.JS/MochaTest/node_modules/brain.js/src/index.js:1
const activation = require('./activation');
                   ^

ReferenceError: require is not defined
    at file:///c:/Coding/Labs/Node.JS/MochaTest/node_modules/brain.js/src/index.js:1:20
    at ModuleJob.run (internal/modules/esm/module_job.js:109:37)
    at async Loader.import (internal/modules/esm/loader.js:133:24)

What should I do and how to import it right when using NodeJS 13.2.0?使用NodeJS 13.2.0时,我应该怎么做以及如何正确导入它? I have only brain.js and Mocha installed in this module.我在此模块中仅安装了brain.js和Mocha。

I'm trying to write a neural network using brain.js.我正在尝试使用brain.js编写神经网络。 However, NodeJS doesn't allow me to do that neither with require('brain.js') nor with import 'brain.js' .但是,NodeJS不允许我同时使用require('brain.js')import 'brain.js'来做到这import 'brain.js' Here is my code:这是我的代码:

const brain = require('brain.js')

const config = {
    iterations: 15000,
    log: true,
    logPeriod: 500,
    layers: [10]
}

const net = new brain.recurrent.LSTM()

const conjunctions = {
    0: 'Именительный',
    1: 'Родительный',
    2: 'Дательный',
    3: 'Винительный',
    4: 'Творительный',
    5: 'Предложный'
}

const inputData = [
    // some data for training
]

const test = 'Дельфина'

net.train(inputData)
const output = net.run(test)
console.log(`${conjunctions[output]} падеж`)

However, it shows me next error when running with require('brain.js') :但是,它显示了使用require('brain.js')运行时的下一个错误:

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module:         c:\Coding\Labs\Node.JS\MochaTest\node_modules\brain.js\src\index.js
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1156:13)
    at Module.load (internal/modules/cjs/loader.js:976:32)
    at Function.Module._load (internal/modules/cjs/loader.js:884:14)
    at Module.require (internal/modules/cjs/loader.js:1016:19)
    at require (internal/modules/cjs/helpers.js:69:18)
    at Object.<anonymous> (c:\Coding\Labs\Node.JS\MochaTest\index.js:1:15)
    at Module._compile (internal/modules/cjs/loader.js:1121:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1160:10)
    at Module.load (internal/modules/cjs/loader.js:976:32)
    at Function.Module._load (internal/modules/cjs/loader.js:884:14) {
      code: 'ERR_REQUIRE_ESM'

} }

And next error when running with import * as brain from 'brain.js' :当使用import * as brain from 'brain.js'运行时,下一个错误import * as brain from 'brain.js'

(node:2648) ExperimentalWarning: The ESM module loader is experimental.
file:///c:/Coding/Labs/Node.JS/MochaTest/node_modules/brain.js/src/index.js:1
const activation = require('./activation');
                   ^

ReferenceError: require is not defined
    at file:///c:/Coding/Labs/Node.JS/MochaTest/node_modules/brain.js/src/index.js:1:20
    at ModuleJob.run (internal/modules/esm/module_job.js:109:37)
    at async Loader.import (internal/modules/esm/loader.js:133:24)

What should I do and how to import it right when using NodeJS 13.2.0?使用NodeJS 13.2.0时,我应该怎么做以及如何正确导入它? I have only brain.js and Mocha installed in this module.我在此模块中仅安装了brain.js和Mocha。

brain js should be installed, you can do it with npm but remember that brain do have system dependencies, Usually people forget to install python (I don't know your system but a lot of server are "empty" when you start using them)应该安装brain js,你可以用npm来做,但记住brain确实有系统依赖,通常人们忘记安装python(我不知道你的系统,但是当你开始使用它们时很多服务器都是“空的”)

Mac OS X Python 2.7 XCode Mac OS X Python 2.7 XCode

Ubuntu/Debian Python 2.7 A GNU C++ environment (available via the build-essential package on apt) libxi-dev Working and up to date OpenGL drivers GLEW pkg-config Ubuntu/Debian Python 2.7 GNU C++ 环境(可通过 apt 上的 build-essential 包获得) libxi-dev 工作和最新的 OpenGL 驱动程序 GLEW pkg-config

windows Python 2.7 Microsoft Visual Studio Build Tools 2015 run in cmd: npm config set msvs_version 2015 run in cmd: npm config set python python2.7 windows Python 2.7 Microsoft Visual Studio Build Tools 2015 在 cmd 中运行:npm config set msvs_version 2015 在 cmd 中运行:npm config set python python2.7

I'm trying to write a neural network using brain.js.我正在尝试使用brain.js编写神经网络。 However, NodeJS doesn't allow me to do that neither with require('brain.js') nor with import 'brain.js' .但是,NodeJS不允许我同时使用require('brain.js')import 'brain.js'来做到这import 'brain.js' Here is my code:这是我的代码:

const brain = require('brain.js')

const config = {
    iterations: 15000,
    log: true,
    logPeriod: 500,
    layers: [10]
}

const net = new brain.recurrent.LSTM()

const conjunctions = {
    0: 'Именительный',
    1: 'Родительный',
    2: 'Дательный',
    3: 'Винительный',
    4: 'Творительный',
    5: 'Предложный'
}

const inputData = [
    // some data for training
]

const test = 'Дельфина'

net.train(inputData)
const output = net.run(test)
console.log(`${conjunctions[output]} падеж`)

However, it shows me next error when running with require('brain.js') :但是,它显示了使用require('brain.js')运行时的下一个错误:

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module:         c:\Coding\Labs\Node.JS\MochaTest\node_modules\brain.js\src\index.js
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1156:13)
    at Module.load (internal/modules/cjs/loader.js:976:32)
    at Function.Module._load (internal/modules/cjs/loader.js:884:14)
    at Module.require (internal/modules/cjs/loader.js:1016:19)
    at require (internal/modules/cjs/helpers.js:69:18)
    at Object.<anonymous> (c:\Coding\Labs\Node.JS\MochaTest\index.js:1:15)
    at Module._compile (internal/modules/cjs/loader.js:1121:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1160:10)
    at Module.load (internal/modules/cjs/loader.js:976:32)
    at Function.Module._load (internal/modules/cjs/loader.js:884:14) {
      code: 'ERR_REQUIRE_ESM'

} }

And next error when running with import * as brain from 'brain.js' :当使用import * as brain from 'brain.js'运行时,下一个错误import * as brain from 'brain.js'

(node:2648) ExperimentalWarning: The ESM module loader is experimental.
file:///c:/Coding/Labs/Node.JS/MochaTest/node_modules/brain.js/src/index.js:1
const activation = require('./activation');
                   ^

ReferenceError: require is not defined
    at file:///c:/Coding/Labs/Node.JS/MochaTest/node_modules/brain.js/src/index.js:1:20
    at ModuleJob.run (internal/modules/esm/module_job.js:109:37)
    at async Loader.import (internal/modules/esm/loader.js:133:24)

What should I do and how to import it right when using NodeJS 13.2.0?使用NodeJS 13.2.0时,我应该怎么做以及如何正确导入它? I have only brain.js and Mocha installed in this module.我在此模块中仅安装了brain.js和Mocha。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM