标签: node-modules

Nodemon 未被识别为内部命令可操作程序或批处理文件

我正在使用 NodeJS,但由于其他一些问题,我再次安装了 Windows。现在我已经全局安装了nodemon,它也显示了C盘中的版本,但是当我尝试运行项目时,它给了我错误:

nodemon 未被识别为内部命令可操作程序或批处理文件

node.js npm node-modules nodemon

0
推荐指数
1
解决办法
2万
查看次数

在 Node.js 和 module.export 中调用类内部的本地方法

所以我有一个类,其中一个函数依赖于另一个函数。该类与模块一起导出。根据我能找到的任何内容,我应该能够使用“this”,但这会引发错误。

例子:

class Test{

  test(){
    console.log('hello');
  }

  dependentMethod(){
    this.test();
  }
}

module.exports = Test;
Run Code Online (Sandbox Code Playgroud)

然而,这会在节点中引发这些错误:

(node:69278) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: Cannot read property 'test' of undefined
(node:69278) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:69278) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): TypeError: Cannot read property 'test' of undefined
Run Code Online (Sandbox Code Playgroud)

如果我把这个函数放在类之外,它会工作得很好。谁能解释为什么会失败?:)

编辑:

这是 server.js 中使用该类的代码(针对示例进行了简化):

const test = …
Run Code Online (Sandbox Code Playgroud)

node.js node-modules ecmascript-6 es6-class

0
推荐指数
1
解决办法
8780
查看次数

NativeScript 安装时缺少写入访问错误

当我尝试通过运行安装 nativescriptt 时npm i -g nativescript,收到以下错误:

    npm WARN checkPermissions Missing write access to 
    /usr/local/lib/node_modules/nativescript
    npm ERR! path /usr/local/lib/node_modules/nativescript
    npm ERR! code ENOENT
    npm ERR! errno -2
    npm ERR! syscall access
    npm ERR! enoent ENOENT: no such file or directory, access 
    '/usr/local/lib/node_modules/nativescript'
    npm ERR! enoent This is related to npm not being able to find a 
    file.
Run Code Online (Sandbox Code Playgroud)

我尝试以 sudo 身份运行该命令并收到相同的结果。我还尝试向该node_modules目录添加写权限。

我在 macOS High Sierra 上运行节点 v10.6.0。

npm node-modules nativescript

0
推荐指数
1
解决办法
1万
查看次数

Moment.js:判断是否已经过去24小时

非常简单,但基本上我需要检查自用户提供特定命令以来是否已经过了 24 小时。(限速1次使用/天)当他们使用该命令时,当前时间被保存并存储,因此没有问题,但当前系统仅对日期起作用,检查是否lastDaily日期部分是否小于当前日期。这会导致命令在午夜重置的情况。

我想这样做,以便如果用户在2:25PMon运行每日命令9/12/2019运行每日命令,他们将无法使用它,直到第二天的同一时间(或下一分钟)。

代码

const fs = require("fs");
const moment = require("moment");
const { RichEmbed } = require("discord.js");
const { m } = require("../../botconfig.json");

module.exports = {
  config: {
    // Command Config: Hidden for space's sake.
  },

  run: async (bot, message, args) => {
    let userData = JSON.parse(fs.readFileSync("db/userdata.json", "utf8"));

    let sender = message.author;

    // Initialise missing data if needed
    if (!userData[sender.id]) { // if there is no userdata,
      userData[sender.id] = {}; // Create …
Run Code Online (Sandbox Code Playgroud)

javascript node.js node-modules momentjs

0
推荐指数
1
解决办法
1846
查看次数

var module = require() 还是 const {module} = require()?

这两个需要方法之间的区别是什么:

1. var xx = require('module')
2. const {xx} = require('module')
Run Code Online (Sandbox Code Playgroud)

我看到第一个 onde 我可以访问 xx 作为变量,所有脚本都由模块导出。第二个 xx 未定义。如何访问第二个“方法”或者它是一种方法来构造模块来使用 {}

谢谢

javascript require node.js node-modules

0
推荐指数
1
解决办法
3929
查看次数

找不到“EXUpdates/EXUpdatesAppController.h”文件

我有一个名为“MyReactNative”的本机反应项目。我已经更新了 React Native 版本(~0.63.3),之后我在运行 iOS 代码时收到以下错误:

找不到“EXUpdates/EXUpdatesAppController.h”文件

这是我的 package.json 的样子:

{
  "main": "index.js",
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "web": "expo start --web",
    "start": "react-native start",
    "test": "jest",
    "build:ios": "node node_modules/react-native/local-cli/cli.js bundle --entry-file='index.js' --bundle-output='./ios/main.jsbundle' --dev=false --platform='ios' --assets-dest='./ios'"
  },
  "dependencies": {
    "@react-native-community/cli-platform-android": "^4.13.0",
    "@react-native-community/masked-view": "^0.1.10",
    "@react-navigation/native": "^5.8.10",
    "@react-navigation/stack": "^5.12.8",
    "axios": "^0.19.0",
    "babel-preset-react-native": "5.0.2",
    "local_package": "file:../local_package-1.6.0.tgz",
    "expo": "~39.0.2",
    "expo-splash-screen": "~0.6.2",
    "expo-status-bar": "~1.0.2",
    "expo-updates": "^0.3.5",
    "nodemon": "^1.18.10",
    "npm-install-peers": "^1.2.1",
    "prop-types": "^15.6.0",
    "react": "17.0.1",
    "react-devtools": "^3.6.1",
    "react-dom": "16.13.1",
    "react-native": "~0.63.3",
    "react-native-axios": "^0.17.1", …
Run Code Online (Sandbox Code Playgroud)

ios node-modules react-native expo

0
推荐指数
1
解决办法
4297
查看次数

使用全局 fastify-cli (mac) 时节点“错误:找不到模块 'node:process'”

我正在设置一台新的 mac 开发机器,并安装了 node、npm 和 nvm。在单个项目目录中一切看起来都很好。但是,当尝试安装和使用时fastify-cli,我收到错误:

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

Error: Cannot find module 'node:process'
Require stack:
- /Users/a/.nvm/versions/node/v14.17.5/lib/node_modules/fastify-cli/node_modules/marked-terminal/index.cjs
- /Users/a/.nvm/versions/node/v14.17.5/lib/node_modules/fastify-cli/node_modules/blessed-contrib/lib/widget/markdown.js
- /Users/a/.nvm/versions/node/v14.17.5/lib/node_modules/fastify-cli/node_modules/blessed-contrib/index.js
- /Users/a/.nvm/versions/node/v14.17.5/lib/node_modules/fastify-cli/docs.js
- /Users/a/.nvm/versions/node/v14.17.5/lib/node_modules/fastify-cli/cli.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:889:15)
    at Function.Module._load (internal/modules/cjs/loader.js:745:27)
    at Module.require (internal/modules/cjs/loader.js:961:19)
    at require (internal/modules/cjs/helpers.js:92:18)
    at Object.<anonymous> (/Users/a/.nvm/versions/node/v14.17.5/lib/node_modules/fastify-cli/node_modules/marked-terminal/index.cjs:3:17)
    at Module._compile (internal/modules/cjs/loader.js:1072:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
    at Module.load (internal/modules/cjs/loader.js:937:32)
    at Function.Module._load (internal/modules/cjs/loader.js:778:12)
    at Module.require (internal/modules/cjs/loader.js:961:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/a/.nvm/versions/node/v14.17.5/lib/node_modules/fastify-cli/node_modules/marked-terminal/index.cjs',
    '/Users/a/.nvm/versions/node/v14.17.5/lib/node_modules/fastify-cli/node_modules/blessed-contrib/lib/widget/markdown.js',
    '/Users/a/.nvm/versions/node/v14.17.5/lib/node_modules/fastify-cli/node_modules/blessed-contrib/index.js',
    '/Users/a/.nvm/versions/node/v14.17.5/lib/node_modules/fastify-cli/docs.js',
    '/Users/a/.nvm/versions/node/v14.17.5/lib/node_modules/fastify-cli/cli.js'
  ]
}
Run Code Online (Sandbox Code Playgroud)

重现步骤:

  1. $ npm install --global fastify-cli(成功)
  2. $ fastify …

node.js npm node-modules fastify

0
推荐指数
1
解决办法
8166
查看次数

无法从另一个JS文件调用函数

得到了一个我无法解决的非常简单的问题。我无法从Node.js中的另一个JavaScript文件调用函数。

我的主文件:

var Binance = require('./binance.js');

//later in the file
app.post('/createBotOrder', function (req, res, next) {
    console.log("in");
    console.log(Binance);
    console.log(Binance.sum(1, 2));
    console.log("in 2");
});
Run Code Online (Sandbox Code Playgroud)

我的辅助文件:

module.exports = function() {
    this.sum = function(a,b) { return a+b };
    this.multiply = function(a,b) { return a*b };
    //etc
}
Run Code Online (Sandbox Code Playgroud)

输出:

in
[Function]
Run Code Online (Sandbox Code Playgroud)

javascript node.js node-modules

-1
推荐指数
1
解决办法
59
查看次数

为什么 git 默认忽略 node_modules 文件夹?

我创建了一个 angular 项目并将其推送到我的github存储库中。

当我查看推送的文件时,该node_modules文件夹丢失了,我没有在任何地方声明忽略该文件夹,这是默认行为吗?如果是,那为什么?

此外,当我决定删除我在 github 上的所有存储库并仅创建一个存储库时,我将在其中签入所有项目,一旦初始化git init并推送更改,git 开始推送node_modules所有项目的文件夹,这花了很多时间。

是什么让git忽略或不忽略node_modules文件夹本身?我自己没有在任何地方设置过这个配置。

谢谢你。

git github gitignore node-modules angular

-1
推荐指数
1
解决办法
1675
查看次数

尝试使用节点安装 graphql 包

npm ERR! code ENOSELF
npm ERR! Refusing to install package with name "graphql" under a package
npm ERR! also called "graphql". Did you name your project the same
npm ERR! as the dependency you're installing?
npm ERR! 
npm ERR! For more information, see:
Run Code Online (Sandbox Code Playgroud)

node.js npm node-modules graphql

-1
推荐指数
1
解决办法
651
查看次数

如何在 npm mydatepicker 中添加自定义样式?

如何在npm mydatepicker 中添加自定义样式?我正在使用此代码:

<my-date-picker [options]="myDatePickerOptions" (dateChanged)="onDateChanged($event)"></my-date-picker>
Run Code Online (Sandbox Code Playgroud)

如何更改其背景颜色和高度宽度?

css node.js npm node-modules angular

-3
推荐指数
1
解决办法
675
查看次数