Express JS: TypeError [ERR_INVALID_ARG_TYPE]: "url" 参数必须是字符串类型。收到型号

Express JS: TypeError [ERR_INVALID_ARG_TYPE]: The "url" argument must be of type string. Received type number

我正在通过这个 TUT 在 shopify 中制作一个私人应用 build-a-shopify-app-with-node-and-react

TUT 使用 koa but I am using express。部分原因是我知道表达并想看看我是否可以抽象出正在发生的事情并将其应用到不同的上下文中。

当我达到 Authenticate and test your app 时,他们希望有人这样做:

Add the HTTPS version of your ngrok forwarding URL and your store’s URL to the following placeholder and load it in a browser:

Tip

导致我的错误:

TypeError [ERR_INVALID_ARG_TYPE]: The "url" argument must be of type string. Received type number
    at Url.parse (url.js:154:11)
    at urlParse (url.js:148:13)
    at Object.urlResolve [as resolve] (url.js:659:10)
    at /Users/antoniopavicevac-ortiz/Sites/scheduled-promo-bar/node_modules/express-shopify-auth/index.js:190:19
    at Function.shop (/Users/antoniopavicevac-ortiz/Sites/scheduled-promo-bar/server/server.js:28:14)
    at middleware (/Users/antoniopavicevac-ortiz/Sites/scheduled-promo-bar/node_modules/express-shopify-auth/index.js:168:25)
    at Layer.handle [as handle_request] (/Users/antoniopavicevac-ortiz/Sites/scheduled-promo-bar/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/Users/antoniopavicevac-ortiz/Sites/scheduled-promo-bar/node_modules/express/lib/router/index.js:317:13)
    at /Users/antoniopavicevac-ortiz/Sites/scheduled-promo-bar/node_modules/express/lib/router/index.js:284:7
    at Function.process_params (/Users/antoniopavicevac-ortiz/Sites/scheduled-promo-bar/node_modules/express/lib/router/index.js:335:12)
    at next (/Users/antoniopavicevac-ortiz/Sites/scheduled-promo-bar/node_modules/express/lib/router/index.js:275:10)
    at session (/Users/antoniopavicevac-ortiz/Sites/scheduled-promo-bar/node_modules/express-session/index.js:468:7)
    at Layer.handle [as handle_request] (/Users/antoniopavicevac-ortiz/Sites/scheduled-promo-bar/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/Users/antoniopavicevac-ortiz/Sites/scheduled-promo-bar/node_modules/express/lib/router/index.js:317:13)
    at /Users/antoniopavicevac-ortiz/Sites/scheduled-promo-bar/node_modules/express/lib/router/index.js:284:7
    at Function.process_params (/Users/antoniopavicevac-ortiz/Sites/scheduled-promo-bar/node_modules/express/lib/router/index.js:335:12)

这是我的 server.js:

/* eslint-disable vars-on-top */
require('isomorphic-fetch');
var express = require('express');
var next = require('next');
var ShopifyAuth = require('express-shopify-auth');
var dotenv = require('dotenv');
var session = require('express-session');

dotenv.config();

const port = parseInt(process.env.PORT, 10) || 3000;
var dev = process.env.NODE_ENV !== 'production';
var app = next({ dev });

var { SHOPIFY_API_SECRET_KEY, SHOPIFY_API_KEY } = process.env;

app.prepare().then(() => {
  var auth = ShopifyAuth.create({
    appKey: SHOPIFY_API_KEY,
    appSecret: SHOPIFY_API_SECRET_KEY,
    baseUrl: port,
    authPath: '/auth',
    authCallbackPath: '/auth/callback',
    authSuccessUrl: '/success',
    authFailUrl: '/fail',
    scope: ['read_products'],
    shop(req, done) {
      return done(null, req.query.shop);
    },
    onAuth(req, res, shop, accessToken, done) {
      // save auth info to session
      req.session.shopify = { shop, accessToken };
      return done();
    },
  });

  var server = express();

  server.use(
    session({
      secret: SHOPIFY_API_SECRET_KEY,
      resave: false,
      saveUninitialized: true,
    })
  );

  server.use(auth);

  server.get('/success', function(req, res) {
    res.json(req.session.shopify);
  });

  server.get('/fail', function(req, res) {
    res.send('Authentication failed');
  });

  server.listen(port, () => {
    console.log(`> Ready on http://localhost:${port}`);
  });
});

有人有什么见解吗?

您正在传递 baseurl 属性 中的端口,这是一个数字。您应该在此处添加 url。