【问题标题】:How to pass the JSON validation of write-manifest.json when adding "debugLocale"?添加“debugLocale”时如何通过write-manifest.json的JSON验证?
【发布时间】:2019-06-04 12:15:30
【问题描述】:

我正在尝试为 Sharepoint Online 构建我的第一个 本地化 SPFX WebPart。我在loc 文件夹中添加了一种额外的语言de-de.js,现在我正在尝试更改write-manifest.json,以便通过向其添加“debugLocale”属性来在调试时使用我的新语言:

{
    "$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

我该如何解决这个问题?

【问题讨论】:

    标签: json sharepoint sharepoint-online spfx


    【解决方案1】:

    在 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"
    }
    

    【讨论】:

    • “buildSingleLocale”的行为与“debugLocale”相同。对我来说,听起来“debugLocale”在部署时会被忽略,而“buildSingleLocale”则不会。
    • 我查看了代码库并比较了 1.5 和 1.6。在确定默认与调试区域设置时进行了一些小的更改。但由于它与配置中的 debugLocale 相关,因此看起来 debugLocale 已切换为 buildSingleLocale。我进行了测试,它按预期工作。
    • "buildSingleLocale" 似乎适用于 loc 文件夹中的本地化文件。但是,.manifest.json 中的本地化条目将被忽略(即 WebPart 的标题和描述),并且会出现警告“不允许使用属性 buildSingleLocale。”
    • 如果您在工作台上谈论,这是真的。工作台不支持 webpart.manifest.json 文件中的本地化条目。至于架构,正确,清单架构中缺少此值,因此您将收到此警告。
    【解决方案2】:

    我刚刚尝试过,它在我的设置中有效。

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

    我的版本:

    • 哟 - 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
    

    【讨论】:

    • 感谢您将问题重定向到 MS。
    • @modiX 如果有帮助,请接受它作为答案。
    猜你喜欢
    • 2022-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-22
    • 2016-08-27
    • 1970-01-01
    相关资源
    最近更新 更多