繁体   English   中英

模板开始错误 - TypeError("参数 'url' 必须是字符串,而不是 " + typeof url)

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

我已经使用 stencil 有一段时间了,正在为它开发自定义主题,我已经安装了 nvm 和 node 5.0 以及 npm 2。我还删除了 stencil 并重新安装了所有内容,包括节点模块和 stencil init 但是不管什么时候运行 stencil start 我仍然得到下面的错误,我已经在谷歌上搜索了这个,结果是空的,所以我希望有人能帮助我。 提前致谢!

  ⇒  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 ) 中设置。 这是应该在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 = Fs.readFileSync(dotStencilFilePath, {encoding: 'utf-8'});
因此dotStencilFile的值是通过从位于dotStencilFilePath磁盘读取文件来设置的。

那么最后一个问题,它的路径是什么? ... dotStencilFilePath的价值是dotStencilFilePath

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

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

这个.stencil文件应该是一个 JSON 文件,其中包含两个 URL 属性的值: storeUrlnormalStoreUrl

我应该检查此文件以确保已设置这些属性。 我应该在stencil init期间设置它们吗? 我可以手动设置它们吗? 无论哪种方式,我都确定主要错误是因为该文件不包含上述两个 URL 的值。



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

我已经解决了这个问题。 url 应该由 Stencil 在 Stencil init 上设置,然后在 Stencil start 上匹配它们。 事实证明,我不知道客户的帐户已变为非活动状态,这意味着它不再存在。 简而言之,url 未定义,因为客户端不再设置 url,因此不再需要定义 url。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM