添加“ debugLocale”时如何通过write-manifest.json的JSON验证?

时间:2019-01-09 16:53:18

标签: json sharepoint sharepoint-online spfx

我正在尝试为Sharepoint Online构建我的第一个本地化 SPFX WebPart。我在de-de.js文件夹中添加了另一种语言loc,现在我想通过将`“ debugLocale”属性添加到write-manifest.json来在调试中使用新的语言。它:

{
    "$schema": "https://developer.microsoft.com/json-schemas/spfx-build/write-manifests.schema.json",
    "cdnBasePath": "<!-- PATH TO CDN -->",
    "debugLocale": "de-de"
}

检查official instructions of Microsoft和检查JSON sheme of the write-manifest.json显示应该编译,但是当我gulp serve返回时:

Build target: DEBUG
./node_modules/@microsoft/node-core-library/lib/JsonSchema.js:178
            throw new Error(prefix + os.EOL +
            ^

    Error: JSON validation failed:
    ./config/write-manifests.json

    Error: #/ (Defines configuration options for the...)
           Additional properties not allowed: debugLocale
        at validateObjectWithCallback (./node_modules/@microsoft/node-core-library/lib/JsonSchema.js:178:19)
        at JsonSchema.validateObjectWithCallback (./node_modules/@microsoft/node-core-library/lib/JsonSchema.js:193:13)
        at JsonSchema.validateObject (./node_modules/@microsoft/node-core-library/lib/JsonSchema.js:175:14)
        at WriteManifestsTask._readConfigFile (./node_modules/@microsoft/gulp-core-build/lib/tasks/GulpTask.js:311:28)
        at WriteManifestsTask.onRegister (./node_modules/@microsoft/gulp-core-build/lib/tasks/GulpTask.js:87:32)
        at Object.initialize (./node_modules/@microsoft/gulp-core-build/lib/index.js:299:24)
        at SPWebBuildRig.initialize (./node_modules/@microsoft/sp-build-common/lib/BuildRig.js:61:19)
        at SPWebBuildRig.initialize (./node_modules/@microsoft/sp-build-common/lib/SPBuildRig.js:29:15)
        at SPWebBuildRig.initialize (./node_modules/@microsoft/sp-build-web/lib/SPWebBuildRig.js:15:15)
        at Object.exports.initialize (./node_modules/@microsoft/sp-build-web/lib/index.js:23:17)
    npm ERR! code ELIFECYCLE
    npm ERR! errno 1
    npm ERR! hello-world@0.0.1 start: `gulp serve`
    npm ERR! Exit status 1
    npm ERR!
    npm ERR! Failed at the hello-world@0.0.1 start script.
    npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

    npm ERR! A complete log of this run can be found in:
    npm ERR!     ~/.npm/_logs/2019-01-09T16_43_53_070Z-debug.log

我该如何解决这个问题?

2 个答案:

答案 0 :(得分:2)

我刚刚尝试过,它可以在我的设置中正常工作。

  1. 使用yo @microsoft/sharepoint和默认选项(使用React作为Javascript框架)创建的webpart
  2. 已将de-de.js文件添加到loc文件夹并更改了值,因此我可以看到它确实是在获取正确的文件
  3. "debugLocale": "de-de"添加到了write-manifests.json
  4. 运行gulp serve
  5. 使用的文字来自de-de.js

我的版本:

  • yo-2.0.3
  • @ microsoft / sharepoint生成器-1.4.1(我知道它很旧了)
  • npm-5.6.0(是,也是旧版本)

但是,一旦我将@microsoft/sharepoint生成器更新为最新版本1.7.1,它便停止工作。该问题似乎是从1.6.0版开始出现的

解决方法是使用--locale之类的gulp serve --locale=de-de参数运行它,或使用旧版本:

npm uninstall @microsoft/generator-sharepoint -g
npm install @microsoft/generator-sharepoint@1.5.1 -g

答案 1 :(得分:2)

在1.5和1.6之间,构建任务似乎已更改。我已经用1.6+确认了这个问题。

如果将write-manfiest.json的“ debugLocale”修改为“ buildSingleLocale”,一切将按预期进行。我认为文档和架构可能已过时。

{
    "$schema": "https://developer.microsoft.com/json-schemas/spfx-build/write-manifests.schema.json",
    "cdnBasePath": "<!-- PATH TO CDN -->",
    "buildSingleLocale": "de-de"
}