小编Dar*_*te1的帖子

在 ES6 Node.js 中导入“.json”扩展会引发错误

我们正在尝试使用 Node.js 为 ES6 导出和导入模块的新方法。从package.json文件中获取版本号对我们来说很重要。下面的代码应该这样做:

import {name, version} from '../../package.json'
Run Code Online (Sandbox Code Playgroud)

但是,在执行时抛出以下错误:^

TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".json" for T:\ICP\package.json imported from T:\ICP\src\controllers\about.js
Run Code Online (Sandbox Code Playgroud)

有什么我们遗漏的吗?不支持
扩展.json吗?
有没有其他方法可以使用 Node.js 13+ 检索此信息?

javascript node.js es6-modules

43
推荐指数
4
解决办法
2万
查看次数

php_mysql.dll发生了什么?

最后,经过几个小时的讨论,我在IIS 7.5 Windows Server 2008上完成了PHP 7.02的安装.所有功能都正常,除了一个错误:

[2016年1月20日15:19:26 UTC] PHP警告:PHP启动:无法加载动态库'D:\ PHP\php-7.0.2-nts-Win32-VC14-x64\ext\php_mysql.dll' - 指定的模块无法找到.在第0行的未知中

检查下载的zip文件操作PHP 7.02时,很明显该文件夹ext不包含名为的文件php_mysql.dll.

所以我的问题是我们在哪里可以获取此文件以避免此错误?

php iis iis-7.5

22
推荐指数
2
解决办法
6万
查看次数

@typescript-eslint/no-unsafe-assignment:任何值的不安全赋值

考虑以下代码:

const defaultState = () => {
  return {
    profile: {
      id: '',
      displayName: '',
      givenName: '',
    },
    photo: '',
  }
}

const state = reactive(defaultState())

export const setGraphProfile = async () => {
  const response = await getGraphProfile()
  state.profile = { ...defaultState().profile, ...response.data }
}
Run Code Online (Sandbox Code Playgroud)

它会生成 ESLint 警告:

@typescript-eslint/no-unsafe-assignment:任何值的不安全赋值。

这意味着 中的属性response.data可能与 中的属性不匹配profile。的回报getGraphProfilePromise<AxiosResponse<any>>. 当然,只需忽略这个 ESLint 警告就可以轻松摆脱它:

// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
state.profile = { ...defaultState().profile, ...response.data }
Run Code Online (Sandbox Code Playgroud)

问题:

  • 如何调整 Promise 中的数据getGraphProfile使其匹配?因为可以创建一个 TS …

javascript typescript eslint

22
推荐指数
2
解决办法
12万
查看次数

PowerShell在新实例中启动脚本

我有一个主脚本有几个选项.当您在菜单中选择1时,将执行操作1,然后您将返回菜单.这工作正常,但我希望能够选择例如8,它在新的PowerShell窗口中启动Permissions脚本的代码块.我想将所有代码放在一个脚本中,而不是调用另一个脚本.

我知道这可以通过几个威胁中的"Start-Process powershell"来完成.这会打开一个新的PowerShell窗口,但不会正确执行Permissions脚本的代码块.任何帮助,将不胜感激.

主脚本:

<# Author: Me #>
# Variables
$User = [Environment]::UserName
$OutputPath = "C:\Users\$User\Downloads\"
# Functions
Function Manager ($u) { 
$m = Get-ADObject -Identity $u.managedBy -Properties displayName,cn
    if($m.ObjectClass -eq "user") { $m.displayName } Else{ $m.cn } } 
# Hit play
do {
  [int]$userMenuChoice = 0
  cls
  while ( $userMenuChoice -lt 1 -or $userMenuChoice -gt 7) {
    Write-Host "PowerShell for dummies"
    Write-Host "__________________________________________________"
    Write-Host "1. Groups created in the last 3 weeks"
    Write-Host …
Run Code Online (Sandbox Code Playgroud)

powershell

20
推荐指数
4
解决办法
5万
查看次数

退出PowerShell函数但继续脚本

这似乎是一个非常非常愚蠢的问题,但我无法弄明白.我试图让函数在找到第一个匹配(匹配)时停止,然后继续执行脚本的其余部分.

码:

Function Get-Foo {
    [CmdLetBinding()]
    Param ()

    1..6 | ForEach-Object {
        Write-Verbose $_
        if ($_ -eq 3) {
            Write-Output 'We found it'

            # break : Stops the execution of the function but doesn't execute the rest of the script
            # exit : Same as break
            # continue : Same as break
            # return : Executes the complete loop and the rest of the script
        }
        elseif ($_ -eq 5) {
            Write-Output 'We found it'
        }
    }
}

Get-Foo -Verbose …
Run Code Online (Sandbox Code Playgroud)

powershell function exit

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

PowerShell从数组中删除项[0]

我正在努力去除数组的第一行(项ID).

$test.GetType()

IsPublic IsSerial Name                                     BaseType                                                                                                      
-------- -------- ----                                     --------                                                                                                      
True     True     Object[]                                 System.Array
Run Code Online (Sandbox Code Playgroud)

列出我尝试的所有选项,$test | gm,它清楚地说明:

Remove         Method                void IList.Remove(System.Object value)                                                                                              
RemoveAt       Method                void IList.RemoveAt(int index)
Run Code Online (Sandbox Code Playgroud)

所以,当我尝试时,$test.RemoveAt(0)我得到错误:

Exception calling "RemoveAt" with "1" argument(s): "Collection was of a fixed size."At line:1 char:1
+ $test.RemoveAt(1)
+ ~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : NotSupportedException
Run Code Online (Sandbox Code Playgroud)

所以我终于在这里发现我的数组需要System.Object是能够使用的类型$test.RemoveAt(0).最佳做法是将脚本开头的所有数组声明为列表吗?或者$collection = ({$test}.Invoke()),如果需要此功能,最好将数组转换为列表?

这两种类型的优点和缺点是什么?谢谢您的帮助.

arrays powershell arraylist

15
推荐指数
5
解决办法
7万
查看次数

eslint 错误对任何值进行不安全的成员访问 ['content-type']

以下代码生成以下 eslint 错误:

@typescript-eslint/no-unsafe-member-access:任何值上的不安全成员访问 ['content-type']。

export const getGraphPhoto = async () => {
  try {
    const response = await getGraphDetails(
      config.resources.msGraphPhoto.uri,
      config.resources.msGraphPhoto.scopes,
      { responseType: 'arraybuffer' }
    )
    if (!(response && response.data)) {
      return ''
    }
    const imageBase64 = new Buffer(response.data, 'binary').toString('base64')
    return `data:${response.headers['content-type']};base64, ${imageBase64}`
  } catch (error) {
    throw new Error(`Failed retrieving the graph photo: ${error as string}`)
  }
}
Run Code Online (Sandbox Code Playgroud)

承诺getGraphDetails回归Promise<AxiosResponse<any>>

问题显然是对象response.headers['content-type']上可能不存在该属性response。为了解决这个问题,我尝试先检查它,但这并没有消除警告:

    if (
      !(response && response.data && response.headers && response.headers['content-type'])
    ) { …
Run Code Online (Sandbox Code Playgroud)

javascript typescript eslint

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

PowerShell ValidateSet

我真的很喜欢这种方式ValidateSet.当您在PowerShell ISE中键入Cmdlet时,它会将选项作为列表提出.

我想知道是否可以从CSV文件中检索值Import-CSV并在Param块中使用它们,以便在构造Cmdlet参数时它们可以在PowerShell ISE的下拉框中使用?有点像$Type现在一样工作,但随后使用导入文件中的值.

Function New-Name {
Param (
    [parameter(Position=0, Mandatory=$true)]
    [ValidateSet('Mailbox','Distribution','Folder','Role')]
    [String]$Type,
    [parameter(Position=1,Mandatory=$true)]
    [String]$Name
)
    Process { 'Foo' }
}
Run Code Online (Sandbox Code Playgroud)

csv validation parameters powershell

13
推荐指数
1
解决办法
9395
查看次数

PowerShell首次出现子串/字符时拆分字符串

我有一个字符串,我想分成2件.第一部分在逗号(,)之前,第二部分是逗号之后的所有内容(包括逗号).

我已经设法在变量中的逗号之前检索第一个部分$Header,但我不知道如何comma在一个大字符串中的第一个之后检索它们,因此它包含

$Content = "Text 1,Text 2,Text 3,Text 4," 
Run Code Online (Sandbox Code Playgroud)

这里可能会显示更多文字,例如文字5,文字6,...

$String = "Header text,Text 1,Text 2,Text 3,Text 4,"

$Header = $String.Split(',')[0] //<-- $Header = "Header text"
Run Code Online (Sandbox Code Playgroud)

string powershell split

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

来自参数的PowerShell自定义错误

一个简单的问题,是否有可能ValidateScript在测试失败时生成自定义错误消息,比如说Test-Path

而不是这个:

测试文件夹:无法验证参数"文件夹"的参数.值为"blabla"的参数的"Test-Path $ _ -Path Type Container"验证脚本未返回True结果.确定验证脚本失败的原因,然后再次尝试使用逗号.

让它在$Error变量中报告它会很高兴:

找不到"文件夹",可能存在网络问题?

码:

Function Test-Folder {
    Param (
        [parameter(Mandatory=$true)]
        [ValidateScript({Test-Path $_ -PathType Container})]
        [String]$Folder
    )
    Write-Host "The folder is: $Folder"
}
Run Code Online (Sandbox Code Playgroud)

解决方法1:

我可以删除Mandatory=$true并更改如下.但这并没有给我正确的Get-Help语法,也没有进行Test-Path验证,因为它只检查参数是否存在.

Function Test-Folder {
    Param (
        [parameter()]
        [String]$Folder = $(throw "The $_ is not found, maybe there are network issues?")
    )
    Write-Host "The folder is: $Folder"
}
Run Code Online (Sandbox Code Playgroud)

解决方法2:

我在博客上找到了这个解决方法,但问题是它产生了2个错误而不是1个错误.

Function Test-Folder {
    Param (
        [parameter(Mandatory=$true)]
        [ValidateScript({ …
Run Code Online (Sandbox Code Playgroud)

parameters powershell

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