node-sppkg-deploy 错误地尝试获取 https://mytenant.sharepoint.com/sites/mysite/AppCatalog/_api/site?$select=Id

node-sppkg-deploy erroneously tries to GET https://mytenant.sharepoint.com/sites/mysite/AppCatalog/_api/site?$select=Id

我正在尝试使用 gulp 上传和部署包。 上传逻辑有效,但当我尝试部署时,出现以下错误:

dev:test-plugins admin$ gulp upload-sequential
Build target: DEBUG
[12:04:50] Using gulpfile /src/test-plugins/gulpfile.js
[12:04:50] Starting gulp
[12:04:50] Starting 'upload-sequential'...
[12:04:51] Uploading testpackage.sppkg
[12:04:52] Upload successful 1523ms
[12:04:52] Published file 333ms
======https://mytenant.sharepoint.com/sites/mysite/AppCatalog
(node:75514) UnhandledPromiseRejectionWarning: Failed to call the API URL: https://mytenant.sharepoint.com/sites/mysite/AppCatalog/_api/site?$select=Id
(node:75514) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:75514) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
About to exit with code: 0
Process terminated before summary could be written, possible error in async code not continuing!
Trying to exit with exit code 1

错误是正确的,没有 URL 和 https://mytenant.sharepoint.com/sites/mysite/AppCatalog/_api/site?$select=Id 一样,我不知道它为什么要尝试获取该站点。

正确的站点是:

 https://mytenant.sharepoint.com/sites/mysite/

目录站点是:

 https://mytenant.sharepoint.com/sites/mysite/AppCatalog

代码

代码如下:

build.task("upload-sequential", {
  execute: async () => {
      const pluginList = require("./config/apps.json");
      if (!pluginList) {
        return;
      }
      for (const { name, sites } of pluginList.plugins) {
        const folderLocation = `./plugins/${name}`;
        if (!sites) {
          //deploy to tenant
        } else {
              for (const site of sites) {
                try{
                      return new Promise((resolve) => {
                        gulp
                          .src(folderLocation)
                          .pipe(
                            spsync({
                              username: uname,
                              password: pwd,
                              site: siteUrl + site,
                              libraryPath: appCatalog,
                              publish: true,
                            })
                          )
                          
                          .on("finish",(resolve)=> {
                            console.log("======" + coreOptions.siteUrl + site + "/" + coreOptions.appCatalog);
                             sppkgDeploy.deploy({
                              username: uname,
                              password: pwd,
                              absoluteUrl: siteUrl + site + "/" + appCatalog,
                              filename: name,
                              skipFeatureDeployment: true,
                              verbose: false
                          })
                        });
                      });
                    }
                    catch (error){
                      console.log("*******");
                      console.log(error);
                      console.log("******");
                    }
                }
            }
      }
  },
});

到目前为止我尝试过的:

我尝试像这样为 node-sppkg-deploy 打开详细日志记录:(最后一行)

 .on("finish",(resolve)=> {
   console.log("======" + coreOptions.siteUrl + site + "/" + coreOptions.appCatalog);
   sppkgDeploy.deploy({
     username: creds.username,
     password: creds.password,
     absoluteUrl: coreOptions.siteUrl + site + "/" + coreOptions.appCatalog,
     filename: name,
     skipFeatureDeployment: true,
     verbose: true
 })

我看到了这种类型的输出:

Build target: DEBUG
[12:02:19] Using gulpfile /src/test-plugins/gulpfile.js
[12:02:19] Starting gulp
[12:02:19] Starting 'upload-sequential'...
[12:02:19] Uploading testpackage.sppkg
[12:02:21] Upload successful 2351ms
[12:02:22] Published file 364ms
======https://mytenant.sharepoint.com/sites/mysite/AppCatalog
ERROR: { StatusCodeError: 404 - undefined
    at new StatusCodeError (/src/test-plugins/node_modules/node-sppkg-deploy/node_modules/request-promise-core/lib/errors.js:32:15)
    at Request.plumbing.callback (/src/test-plugins/node_modules/node-sppkg-deploy/node_modules/request-promise-core/lib/plumbing.js:104:33)
    at Request.RP$callback [as _callback] (/src/test-plugins/node_modules/node-sppkg-deploy/node_modules/request-promise-core/lib/plumbing.js:46:31)
    at Request.self.callback (/src/test-plugins/node_modules/node-sppkg-deploy/node_modules/request/request.js:188:22)
    at Request.emit (events.js:198:13)
    at Request.<anonymous> (/src/test-plugins/node_modules/node-sppkg-deploy/node_modules/request/request.js:1171:10)
    at Request.emit (events.js:198:13)
    at IncomingMessage.<anonymous> (/src/test-plugins/node_modules/node-sppkg-deploy/node_modules/request/request.js:1091:12)
    at Object.onceWrapper (events.js:286:20)
    at IncomingMessage.emit (events.js:203:15)
    at endReadableNT (_stream_readable.js:1145:12)
    at process._tickCallback (internal/process/next_tick.js:63:19)
  name: 'StatusCodeError',
  statusCode: 404,
  message: '404 - undefined',
  error: undefined,
  options:
   { method: 'GET',
     url:
      'https://mytenant.sharepoint.com/sites/mysite/AppCatalog/_api/site?$select=Id',
     resolveWithFullResponse: true,
     simple: true,
     headers:

此外,尝试在节点 sppkg 部署调用中使用租户和站点属性,但我遇到了同样的错误。

我在同一站点上使用相同的凭据手动上传并部署了程序包,并且工作正常。

我不确定还要检查什么。如有任何建议,我们将不胜感激。

你没有兑现承诺。我在 on(finish).

中添加了一个 resolve()

另外,我认为你应该等待你的承诺,而不是返回它们。

还有一点就是你可能需要在你的gulp.pipe中处理错误,一旦出现错误,你应该reject()。这部分逻辑我加进去了,大家可以看看

build.task("upload-sequential", {
  execute: async () => {
    const pluginList = require("./config/apps.json");
    if (!pluginList) {
      return;
    }
    for (const { name, sites } of pluginList.plugins) {
      const folderLocation = `./plugins/${name}`;
      if (!sites) {
        //deploy to tenant
      } else {
        for (const site of sites) {
          try {
            await new Promise((resolve, reject) => {
              gulp
                .src(folderLocation)
                .pipe(
                  spsync({
                    username: uname,
                    password: pwd,
                    site: siteUrl + site,
                    libraryPath: appCatalog,
                    publish: true,
                  })
                )
                .on("error", reject)
                .on("finish", resolve);
            });

            sppkgDeploy.deploy({
              username: uname,
              password: pwd,
              absoluteUrl: siteUrl + site + "/" + appCatalog,
              filename: name,
              skipFeatureDeployment: true,
              verbose: false,
            });
          } catch (error) {
            console.log(error);
            throw new Error(error);
          }
        }
      }
    }
  },
});