【问题标题】:nodejs: IJavascript: says module not foundnodejs:IJavascript:说找不到模块
【发布时间】:2021-04-26 06:21:32
【问题描述】:

我已经在 linux pc 上安装了 Ijavascript

sudo npm install -g ijavascript

我已经安装了mathsteps

sudo npm install -g mathsteps

现在我尝试打开 ijsnotebook

ijsnotebook

我启动了一个 javascript(node.js) shell

现在我正在尝试来自https://github.com/google/mathsteps#usage的以下代码示例

const mathsteps = require('mathsteps');

const steps = mathsteps.simplifyExpression('2x + 2x + x + x');

steps.forEach(step => {
    console.log("before change: " + step.oldNode.toString());   // before change: 2 x + 2 x + x + x
    console.log("change: " + step.changeType);                  // change: ADD_POLYNOMIAL_TERMS
    console.log("after change: " + step.newNode.toString());    // after change: 6 x
    console.log("# of substeps: " + step.substeps.length);      // # of substeps: 3
});

我收到此错误:

internal/modules/cjs/loader.js:657
    throw err;
    ^

Error: Cannot find module 'mathsteps'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:655:15)
    at Function.Module._load (internal/modules/cjs/loader.js:580:25)
    at Module.require (internal/modules/cjs/loader.js:711:19)
    at require (internal/modules/cjs/helpers.js:14:16)
    at evalmachine.<anonymous>:1:19
    at Script.runInThisContext (vm.js:124:20)
    at Object.runInThisContext (vm.js:314:38)
    at run ([eval]:1054:15)
    at onRunRequest ([eval]:888:18)
    at onMessage ([eval]:848:13)

我该如何解决这个错误。我想检查这段代码。

【问题讨论】:

  • 可能与全局模块有关。在本地尝试(在目录中,没有sudo-g)看看是否有帮助。

标签: node.js ijavascript


【解决方案1】:

首先我尝试了全局安装,但遇到了同样的问题。但是,在我进行本地安装后,我不再有声明 const mathsteps = require('mathsteps'); 的问题。

在他们的repo中,我找到了作者写的解释:

iJavascript 只能看到自身本地的包和用户本地的包

你可以在这里找到整个对话:Set up working directory

【讨论】:

    猜你喜欢
    • 2011-12-13
    • 2019-01-02
    • 2021-03-28
    • 2017-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-15
    • 2021-10-18
    相关资源
    最近更新 更多