小编GN.*_*GN.的帖子

构建失败:`npm rebuild node-sass --force`

使用n切换节点版本。我碰到yarnnpm rebuild node-sass --force很多很多次。仍然失败。收到此错误:

Node Sass could not find a binding for your current environment

This usually happens because your environment has changed since running `npm install`.
Run `npm rebuild node-sass --force` to build the binding for your current environment.
Run Code Online (Sandbox Code Playgroud)

有人知道如何解决吗?

另外..运行此命令时..

npm rebuild node-sass --force
Run Code Online (Sandbox Code Playgroud)

我知道了

npm WARN using --force I sure hope you know what you are doing.
Run Code Online (Sandbox Code Playgroud)

似乎什么也没做。

javascript node-sass

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

Eslint将流类型报告为语法错误

如果我正在使用流程.. https://flowtype.org/

// @flow
var foo = (str: string) => {
  return str;
};
Run Code Online (Sandbox Code Playgroud)

和Eslint在一起,Eslint报告意外的令牌str: string.

有没有办法让Eslint忽略(或识别)流类型而不将它们报告为错误?

javascript eslint flowtype

7
推荐指数
1
解决办法
4052
查看次数

用空白值初始化反应号输入控件?

我希望我的受控输入在框中没有任何值的情况下进行初始化。输入是一个数字,因此我不会传递空值''。使用defaultProps,我将输入初始化为null。

在输入中输入时,控制台将报告以下消息:

<MyInput>正在更改要控制的类型编号的不受控制的输入。输入元素不应从不受控制切换为受控制(反之亦然)。

为了防止这种情况,我通常使用一个空字符串进行初始化,以防止发生这种“切换”。但是有一个数字(我不想显示0,我不想显示任何东西)我不确定该怎么做。

static defaultProps = {
    estimatedHours: null,
    estimatedMinutes: null,
  }
Run Code Online (Sandbox Code Playgroud)

默认值^^

<input
   type="number"
   onChange={(e) => this.handleChange('Hours', e.target.value)}
   onKeyDown={this.handleKeyDown}
   onPaste={this.handlePaste}
   value={estimatedHours}
   placeholder={hoursText}
   className="slds-input th-trailmix-textbox th-time-component__input"
/>
Run Code Online (Sandbox Code Playgroud)

javascript reactjs

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

是否可以在浏览器中使用路径模块?

是否可以使用Webpack在浏览器中使用路径模块(例如path.parse)?总是出错parse is not a function。谢谢。

node.js webpack

7
推荐指数
1
解决办法
7314
查看次数

Angular File Upload指令不更新控制器模型

我试图遵循这个[教程],但无法让它工作.

我的Angular控制器正在记录undefined在我的指令中创建的模型.这是一个[JSFiddle]的工作创建了我的教程作者.

问题是视图可以找到$scope.myFile,但控制器没有($scope.myFileundefined).

视图显示{{ myFile.name }}(仅作为示例my-image.jpg).该myFile变量是一个包含所选文件数据的JS对象.这很好用.该指令似乎是为模型分配所选文件的值(因此在视图中正确显示它).

<input file-model="myFile" type="file"/ >
<div class="label label-info">
  {{ myFile.name }}
</div>
<button ng-click="uploadDocs()">Click</button>
Run Code Online (Sandbox Code Playgroud)

这是我从这个[教程]得到的指令.

由于输入类型file无法使用ng-model,因此该指令将模型设置为与file输入关联,并在每次文件触发change事件时为其分配.

directive('fileModel', [
  '$parse',
    function ($parse) {
      return {
        restrict: 'A',
        link: function(scope, element, attrs) {
          var model = $parse(attrs.fileModel);
          var modelSetter = model.assign;

          element.bind('change', function(){
            scope.$apply(function(){
              if (element[0].files.length > 1) { …
Run Code Online (Sandbox Code Playgroud)

javascript angularjs angularjs-directive angularjs-scope

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

Gulp/Browserify中的Redux NODE_ENV错误

我在React/Redux应用程序上收到此错误消息,该应用程序已缩小并与Browserify和Gulp一起打包并部署到Heroku.

bundle.js:39 You are currently using minified code outside of NODE_ENV === 'production'. This means that you are running a slower development build of Redux.

但似乎构建步骤正在进行中NODE_ENV = 'production'.

我有一个设置env变量的任务

gulp.task('apply-prod-environment', function() {
  return process.env.NODE_ENV = 'production';
});
Run Code Online (Sandbox Code Playgroud)

Heroku上的日志显示ENV正在生产:

在此输入图像描述

为了保证在apply-prod-environment 其他任务之前运行,我正在使用RunSequenceGulp插件.

gulp.task('buildProd', cb => {
  runSequence(
    'apply-prod-environment',
    'task-1',
    'task-2',
    'etc',
    cb
  );
});
Run Code Online (Sandbox Code Playgroud)

编辑
第二次尝试..

import envify from 'envify/custom';

function buildJS(sourceFile, {setEnv}) {
  return browserify(sourceFile)
    .transform(babelify, {
      presets: ['es2015', 'react', 'stage-2']
    })
    .transform(envify({
      NODE_ENV: setEnv
    })) …
Run Code Online (Sandbox Code Playgroud)

javascript browserify reactjs gulp redux

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

NextJS 服务器端可以设置断点吗?

是否可以在 NextJS 服务器端代码中设置断点?我有一个debugger在我的getInitialProps,它永远不会在这一点上中断。它仅在浏览器上运行时才会中断,服务器端断点似乎永远不会捕获。

next.js

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

Typescript 混淆:如何使用自定义和 DefinelyTyped 库扩展 Express `Request`?

如何Request在 Typescript / Express 中扩展和使用扩展类型?

我添加了一堆中间件库,其中extendObject Request. IE One 添加user到要求中。另一个添加cookie()到需求。另一个添加csrfToken()到需求。ETC..

当我添加请求处理函数时,如何告诉该函数使用req中间件添加的所有功能?

我是否要查找DefinitelyTyped与中间件对应的每个包?如果是这样,那么该Request类型是否会被这些属性神奇地“装饰”?

为了让它变得更加困难,我编写了自己的中间件,将属性添加到Request

req.myCustomFunction()

在这种情况下,我需要声明并Request使用 myCustomFunction 扩展 self 吗?

此外,Request我扩展的内容是否会“包括”给出的类型DefinitelyTyped

declare namespace Express {
  export interface Request {
    myCustomFunction: () => void
  }
}
Run Code Online (Sandbox Code Playgroud)

DefinitelyTyped现在这将包括通过AND my包含的所有属性吗myCustomFunction

使用时如何引用这个接口?

那将会Express.Request?要不就Request

如果我将其引用为Request,Typescript 如何知道使用“我的”请求而不是 ExpressDefinitelyTyped库导出的请求?

express typescript

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

Typescript Postmessage 失败,只有一个参数,还有两个

有打字稿项目。

当这个: postMessage(result);

我明白了。。

Expected 2-3 arguments, but got 1.预期 2-3 个参数,但得到 1 个。

当这个: postMessage(result, '*');

我明白了。。

Uncaught TypeError: Failed to execute 'postMessage' on 'DedicatedWorkerGlobalScope': Overload resolution failed.
    at runParser
Run Code Online (Sandbox Code Playgroud)

Typescript 在这里想要什么?是一两个论据吗?为什么这会导致问题?

typescript

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

类型“cy &amp; EventEmitter”上不存在属性“app”

来自Cypress on Rails的源代码

// spec/cypress/support/on-rails.ts

Cypress.Commands.add('app', function (name, command_options) {
  return cy
    .appCommands({ name: name, options: command_options })
    .then((body) => {
      return body[0];
    });
});

Run Code Online (Sandbox Code Playgroud)

spec/cypress/tsconfig.json

{
  "compilerOptions": {
    "strict": true,
    "target": "es5",
    "lib": ["es6", "dom"],
    "module": "es6",
    "moduleResolution": "node",
    "sourceMap": false,
    "types": ["cypress"],
    "downlevelIteration": true,
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true
  },
  "include": ["**/*.ts"]
}

Run Code Online (Sandbox Code Playgroud)

结果是

 Property 'app' does not exist on type 'cy & EventEmitter'.
Run Code Online (Sandbox Code Playgroud)

cypress

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