模版启动错误-类型错误(“参数”url'必须是字符串,而不是“+类型的url”)

Stencil Start Error - TypeError("Parameter 'url' must be a string, not " + typeof url)

本文关键字:url 类型 错误 字符串 启动 参数      更新时间:2023-09-26

我已经使用模具工作了一段时间,正在为它开发一个自定义主题,我已经安装了nvm和node5.0以及npm2。我也删除了模具,并重新安装了所有的东西,包括节点模块和模具初始化。但无论怎样,当运行模具启动时,我仍然会收到下面的错误,我已经在谷歌上搜索过了,结果是空的,所以我希望有人能帮我。提前感谢!

  ⇒  stencil start
url.js:110
    throw new TypeError("Parameter 'url' must be a string, not " + typeof url)
          ^
TypeError: Parameter 'url' must be a string, not undefined
    at Url.parse (url.js:110:11)
    at Object.urlParse [as parse] (url.js:104:5)
    at module.exports (/usr/local/lib/node_modules/@bigcommerce/stencil-cli/server/index.js:14:31)
    at startServer (/usr/local/lib/node_modules/@bigcommerce/stencil-cli/bin/stencil-start:188:5)
    at /usr/local/lib/node_modules/@bigcommerce/stencil-cli/bin/stencil-start:166:32
    at /usr/local/lib/node_modules/@bigcommerce/stencil-cli/server/lib/stencil-token.js:55:24
    at finish (/usr/local/lib/node_modules/@bigcommerce/stencil-cli/node_modules/wreck/lib/index.js:137:20)
    at wrapped (/usr/local/lib/node_modules/@bigcommerce/stencil-cli/node_modules/hoek/lib/index.js:866:20)
    at ClientRequest.onResponse (/usr/local/lib/node_modules/@bigcommerce/stencil-cli/node_modules/wreck/lib/index.js:158:20)
    at ClientRequest.g (events.js:199:16)

我从未使用过模具,但由于未在模具配置文件(./.stencil)中设置URL,因此引发了此错误。这是应该在stencil init期间设置的内容吗

具体来说,您需要确保在.stencil文件(我假设它是一个JSON配置文件,位于您的项目根目录中)中设置了这两个值:

  1. storeUrl----------------//安全页面的url(提示为登录页面)
  2. normalStoreUrl---//主页的主机url

了解如何调试Node错误可能会很有用。以下是我在阅读中的思考过程;调试:

1.

TypeError: Parameter 'url' must be a string, not undefined
at Url.parse (url.js:110:11)
at Object.urlParse [as parse] (url.js:104:5)

所以这个错误是非常直接的。程序试图从字符串中解析URL,但该字符串未定义,因此导致了主要错误。具体地,节点模块url.js正在尝试进行解析。

URL应该在哪里定义?让我们继续看看我们是否能解决这个问题。

2:

at module.exports (/usr/local/lib/node_modules/@bigcommerce/stencil-cli/server/index.js:14:31)

https://github.com/bigcommerce/stencil-cli/blob/master/server/index.js
好的,让我们打开这个文件,看看第14行,上面写着:

module.exports = function(options, callback) {
    var config = manifest.get('/'),
        parsedSecureUrl = Url.parse(options.dotStencilFile.storeUrl), //Line 14 - The url to a secure page (prompted as login page)
        parsedNormalUrl = Url.parse(options.dotStencilFile.normalStoreUrl); //The host url of the homepage;
...

好的,我们已经找到了抛出错误的确切行(parsedSecureUrl)。该URL应包含在用于初始化该模块(module.exports = function(options, callback) {})的选项对象中

需要不断挖掘,看看这个选项对象是在哪里定义的,以及它是如何包含其dotStencilFile属性(options.dotStencilFile)的。

3:

at startServer (/usr/local/lib/node_modules/@bigcommerce/stencil-cli/bin/stencil-start:188:5)

https://github.com/bigcommerce/stencil-cli/blob/master/bin/stencil-start上面写着:

 /**
 * Starts up the local Stencil Server as well as starts up BrowserSync and sets some watch options.
 */
function startServer() {
    var params = {
        dotStencilFile: dotStencilFile,   //It's getting set here!!
        variationIndex: themeConfig.variationIndex || 0,
        stencilEditorEnabled: Program.themeEditor,
        stencilEditorPort: Program.themeEditorPort || 8181,
        useCache: Program.cache
    };
    //Line 188 below:
    Server(params, function (err) {
        var watchFiles = [
            '/assets',
            '/templates',
            '/lang'
        ];
    ...

因此,我们在步骤2中找到了负责初始化并将options参数传递给模块的函数。具体来说,变量被称为params,而应该包含URL的对象是params.dotStencilFile

在这一点上,我们只需要弄清楚dotStencilFile应该是什么

4:

通过搜索该文件中的源代码,我可以看到dotStencilFile是通过以下方式声明的:dotStencilFile = Fs.readFileSync(dotStencilFilePath, {encoding: 'utf-8'});
所以dotStencilFile的值是通过从磁盘读取位于dotStencilFilePath的文件来设置的。

最后一个问题是,它的路径是什么。。。dotStencilFilePath的值是多少?

对我们来说很容易,它的价值在同一个文件中定义:
var dotStencilFilePath = Path.join(themePath, '.stencil');
其中themePath=var themePath = process.cwd();(该文件的当前工作目录,假定为项目根目录)。

5:(解决方案)
好吧,我们明白了!应该包含URL的文件称为.stencil(隐藏文件),位于项目根目录(/Users/rob/myStencilProject/.stencil)中。

这个CCD_ 23文件应该是一个JSON文件,它包含两个URL属性的值:storeUrl&normalStoreUrl

我应该检查这个文件以确保已经设置了这些属性。也许我应该在stencil init期间设置它们吗?我可以手动设置吗?无论哪种方式,我确信主要错误是由这个文件不包含上面两个URL的值引起的。



Welp,我希望这些信息有助于解决您当前的问题,以及您在开发过程中可能遇到的任何其他问题。祝你好运

我已经解决了这个问题。url应该由模具在stencil init上设置,然后在stencil start上匹配它们。事实证明,在我不知情的情况下,客户的账户已经不活跃,这意味着它不再存在。简言之,url出现了未定义的情况,因为客户端不再设置url,因此不再需要定义url。