小编Fel*_*Dev的帖子

sudo:npm:找不到命令

我正在尝试升级到最新版本的节点.我按照http://davidwalsh.name/upgrade-nodejs上的说明进行操作

但当我这样做时:

sudo npm install -g n
Run Code Online (Sandbox Code Playgroud)

我收到错误:

sudo: npm: command not found
Run Code Online (Sandbox Code Playgroud)

npm没有sudo.当我做:

whereis node
Run Code Online (Sandbox Code Playgroud)

我知道了:

node: /usr/bin/node /usr/lib/node /usr/bin/X11/node /usr/local/node
Run Code Online (Sandbox Code Playgroud)

运行:

which npm
Run Code Online (Sandbox Code Playgroud)

显示:

/usr/local/node/bin/npm
Run Code Online (Sandbox Code Playgroud)

我在/sf/answers/354390291/上尝试了该解决方案

但我仍然得到同样的错误.我还查看了/ etc/sudoers文件,相关的行是:

Defaults        secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
Run Code Online (Sandbox Code Playgroud)

这看起来很好.我怎样才能让NPM使用sudo命令?

unix node.js npm

162
推荐指数
14
解决办法
52万
查看次数

如何将参数传递给 on:click in Svelte?

将函数绑定到按钮非常简单直接:

<button on:click={handleClick}>
    Clicks are handled by the handleClick function!
</button>
Run Code Online (Sandbox Code Playgroud)

但是当我这样做时,我没有看到将参数(参数)传递给函数的方法:

<button on:click={handleClick("parameter1")}>
    Oh no!
</button>
Run Code Online (Sandbox Code Playgroud)

该函数在页面加载时被调用,并且永远不会再次调用。

是否有可能将参数传递给从 调用的函数on:click{}


**编辑:**

我刚刚找到了一个hacky的方法来做到这一点。从内联处理程序调用该函数有效。

<button on:click={() => handleClick("parameter1")}>
    It works...
</button>
Run Code Online (Sandbox Code Playgroud)

svelte svelte-3

54
推荐指数
3
解决办法
2万
查看次数

如何在多个文件中设置mocha测试用例的执行顺序

我有两个包含mocha测试用例的javascript文件.

//----------abc.js -------------

describe("abc file", function(){
  it("test 1" , function(){
    assert.equal(20 , 20); 
  });
}); 

//---------xyz.js--------------
describe("xyz file", function(){
      it("test 1" , function(){
        assert.equal(10 , 10); 
      });
    });
Run Code Online (Sandbox Code Playgroud)

我把它们放在一个名为的文件夹中test,当我执行mocha命令时,第一个文件(abc.js)总是在xyz.js之前执行.我认为这可能是由于按字母顺序排列并将文件重命名为

abc.js => xyz.js
xyz.js => abc.js
Run Code Online (Sandbox Code Playgroud)

但是,仍然首先执行xyz.js(先前的abc.js)的内容.如何更改这些测试文件的执行顺序?

javascript tdd mocha.js node.js

41
推荐指数
6
解决办法
3万
查看次数

如何禁用:[js] File是一个CommonJS模块; 它可能会转换为ES6模块

以下是我要禁用的内容:

[js] File是一个CommonJS模块;  它可能会转换为ES6模块.

我在设置中找不到它.
帮助赞赏,因为这真的很烦人.

visual-studio-code

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

如何从 FaunaDB 的集合中获取所有文档?

我已经有了答案:

const faunadb = require('faunadb')
const q = faunadb.query

exports.handler = async (event, context) => {
  const client = new faunadb.Client({
    secret: process.env.FAUNADB_SERVER_SECRET
  }) 

  try {  
    // Getting the refs with a first query
    let refs = await client.query(q.Paginate(q.Match(q.Index('skus'))))
    // Forging a second query with the retrieved refs
    const bigQuery = refs.data.map((ref) => q.Get(ref))
    // Sending over that second query
    let allDocuments = await client.query(bigQuery)
    // All my documents are here!
    console.log('@allDocuments: ', allDocuments);
    //...
  } catch (err) {
    // …
Run Code Online (Sandbox Code Playgroud)

node.js faunadb

9
推荐指数
2
解决办法
4776
查看次数

-rc在语义版本控制中是什么意思?

我得到了MAJOR.MINOR.PATCH的逻辑,并在直觉上得到了-alpha和-beta在semver数字末尾的含义,但是-rc对我来说没有任何响声。

在那里找不到令人满意的答案-> https://semver.org/

semantic-versioning

7
推荐指数
3
解决办法
2511
查看次数

如何在vscode中搜索调试控制台?

目前,这是一项功能请求,因此我知道答案并非直截了当,但我认为有些聪明的人为此找到了聪明的解决方法。

一种方法是在某些文本编辑器中复制/粘贴输出,但注意。

有人建议将调试输出重定向到具有搜索功能的终端,听起来更好。

因此,问题是,如何将调试输出重定向到终端?

当然,除非您有更好的解决方案。

编辑(来自GitHub线程)

您可以在调试启动任务上使用属性“ console”:“ integratedTerminal”将输出重定向到终端。

visual-studio-code

7
推荐指数
2
解决办法
2332
查看次数

如何使用纯 JavaScript 检测全屏 api 支持?

这是我指的 API: https: //developer.mozilla.org/en-US/docs/Web/API/Fullscreen_API

至于到目前为止我所尝试过的:

Modernizr 有这个Modernizr.fullscreen东西,但我不想使用另一个库来完成看似简单的任务。

所以我正在挖掘 Modernizr 的源代码来尝试看看他们是如何做到这一点的,毕竟 Modernizr 确实使用 JS 来解决它,对吧?但到目前为止,我在源代码中发现的有关全屏 API 的就是这个文件(Modernizr/feature-detects/fullscreen-api.js)

/*!
{
  "name": "Fullscreen API",
  "property": "fullscreen",
  "caniuse": "fullscreen",
  "notes": [{
    "name": "MDN Docs",
    "href": "https://developer.mozilla.org/en/API/Fullscreen"
  }],
  "polyfills": ["screenfulljs"],
  "builderAliases": ["fullscreen_api"]
}
!*/
/* DOC
Detects support for the ability to make the current website take over the user's entire screen
*/
define(['Modernizr', 'prefixed'], function(Modernizr, prefixed) {
  // github.com/Modernizr/Modernizr/issues/739
  Modernizr.addTest('fullscreen', !!(prefixed('exitFullscreen', document, false) || prefixed('cancelFullScreen', document, false)));
});
Run Code Online (Sandbox Code Playgroud)

...我不太明白该代码。然而。

javascript cross-browser

6
推荐指数
1
解决办法
1183
查看次数

“ message”:“用于调用Google Play开发人员API的项目ID尚未在Google Play开发人员控制台中链接。”

我正在尝试使用以下API下载针对Android Apps的评论。 https://developers.google.com/android-publisher/api-ref/reviews

但这需要身份验证。因此,我按照上面链接中链接的说明进行操作。

我能够获得访问令牌。

但是我得到以下回应:

{
 "error": {
  "errors": [
   {
    "domain": "androidpublisher",
    "reason": "projectNotLinked",
    "message": "The project id used to call the Google Play Developer API has not been linked in the Google Play Developer Console."
   }
  ],
  "code": 403,
  "message": "The project id used to call the Google Play Developer API has not been linked in the Google Play Developer Console."
 }
}
Run Code Online (Sandbox Code Playgroud)

我看到其他一些帖子说,您必须将其与Google Play开发者控制台关联。所以我做到了(见下图)。

[Google Play控制台,链接的项目]

但是我仍然收到此错误。请帮忙。

google-api google-api-client google-console-developer google-play-developer-api google-developers-console

5
推荐指数
2
解决办法
3015
查看次数

让 VS Code 忽略 /var/folders/ 下的文件

当我在 VS Code 中使用“转到文件...”功能(在 mac 上为command+ P)时,VS Code 会列出该/var/folders/...路径下的文件。

命令面板的屏幕截图

选择下面的文件之一/var/folders/通常会产生“无法打开编辑器,因为找不到文件。”。

我很确定这些是 Git 使用的临时文件。当我使用 git 历史功能时,下面的文件var/folders/显示为“最近打开”;将文件与其自身的先前版本进行比较。

有没有办法设置 VS Code 以便只显示当前工作目录中的文件?

macos visual-studio-code

5
推荐指数
1
解决办法
432
查看次数

如何在JavaScript中检测"不同的对象类型"?(阵列vs Json vs Date等......)

为了在递归迭代JSON对象时创建条件,我试图找到一种区分不同对象类型的简洁方法.

考虑一下:

var aJSON     = {"foo" : 1, "bar" : 2};
var anArray   = [1,2,3,4,5];
var aDate     = new Date('2013-03-10T02:00:00Z');
var anISODate = user.timesTheyLoggedIn[0] // comes from MongoDB

console.log(typeof aJSON);     // object
console.log(typeof anArray);   // object
console.log(typeof aDate);     // object
console.log(typeof anISODate); // object
Run Code Online (Sandbox Code Playgroud)

所有类型的对象都是"对象",没有更多信息.

现在,我的用例只需要检测一个ISODate对象,所以我利用具有resetTime函数的ISODate对象将它们与其他对象区分开来,如下所示:

if (typeof(val) === "object" && val.resetTime === undefined) { //do stuff...
Run Code Online (Sandbox Code Playgroud)

但是必须有一种更清洁,更好的方法来检测物体是什么类型的物体,val.isArray()有点像......

怎么会这样?

PS:"不同的对象类型"在引号中,因为JS中只有一个对象类型,对吧?

javascript

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

我想更改 chakra ui 按钮的默认样式

我正在使用 Chakra ui。
我想将按钮颜色更改为#2477b3。我可以通过传递props中的值来改变它,但是每次传递props中的值需要花费很多时间和精力,所以我想改变默认的Button颜色等,
我想使用的样式A 按钮。
我更改了theme.ts并创建了BButton,但样式没有改变。我尝试更改 theme.ts 中的值,但颜色没有改变。

  <Button
      size={'sm'}
      bg="#2B6CB0"
      _hover={{ bg: '#2477b3' }}
      _active={{
        bg: '#2477b3',
        transform: 'scale(0.98)',
        borderColor: '#2477b3',
      }}
      color={'#ffffff'}
    >
     AButton
    </Button>

  <Button>BButton</Button>
Run Code Online (Sandbox Code Playgroud)

主题.ts

import { extendTheme } from '@chakra-ui/react';
export const theme = extendTheme({
  components: {
    Button: {
      baseStyle: {
        fontWeight: 'bold',
        _hover: {
          _disabled: {
            bg: '#2477b3',
          },
        },
      },
      variants: {
        bg: '#2B6CB0',
        _active: {
          bg: '#2477b3',
          transform: 'scale(0.98)',
          borderColor: '#2477b3',
        },
      },
    },
  },
});
Run Code Online (Sandbox Code Playgroud)

reactjs next.js chakra-ui

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