Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
525 views
in Technique[技术] by (71.8m points)

javascript - 无法将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'来做到这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:CodingLabsNode.JSMochaTest ode_modulesrain.jssrcindex.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:CodingLabsNode.JSMochaTestindex.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。)   ask by SM Melamed translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

Please log in or register to reply this article.

OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...