Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

编译阶段错误:Cannot read property 'prefix' of null #67

Closed
wangzexi opened this issue Mar 14, 2017 · 7 comments
Closed

编译阶段错误:Cannot read property 'prefix' of null #67

wangzexi opened this issue Mar 14, 2017 · 7 comments

Comments

@wangzexi
Copy link

wangzexi commented Mar 14, 2017

现有组件引用关系:page->typeMenu->Menu

发现,将typeMenu组件放在某些目录,比如非src/components目录中时,都会在编译时输出下面错误。

[18:17:49] [写入] WXSS: dist/pages/food/com/typeMenu.wxss
TypeError: Cannot read property 'prefix' of null
    at Document.nodeSerializeToString [as toString] (/usr/local/lib/node_modules/wepy-cli/node_modules/.0.1.27@xmldom/dom.js:920:22)
    at /usr/local/lib/node_modules/wepy-cli/lib/compile-template.js:295:50
    at process._tickCallback (internal/process/next_tick.js:103:7)
    at Module.runMain (module.js:606:11)
    at run (bootstrap_node.js:394:7)
    at startup (bootstrap_node.js:149:9)
    at bootstrap_node.js:509:3

import的相对路径我都仔细检查过,没问题。

// typeMenu.wpy

import wepy from 'wepy';
import Menu from '../../../components/menu';

export default class extends wepy.component {
    components = {
        Menu // 当注释掉此行时,报错消失
    };

想请教一下,产生这个错误的原因?

@liumin1128
Copy link

liumin1128 commented Mar 14, 2017

如果我没猜错的话,你的组件代码需要改成:
components = { menu: Menu };
然后组件中使用
<menu />
,是的你没看错,需要小写,这个不是React组件,而是自定义标签。
当然也可能是组件名和变量名冲突。

@sqaiyan
Copy link

sqaiyan commented Mar 15, 2017

我昨天遇到过, template里不能直接写component,需要用view包住一层,不知道你的是不是这个问题,可以试试看

@Gcaufy
Copy link
Collaborator

Gcaufy commented Mar 15, 2017

@liumin1128
他的写法没有问题,可以写

components = {
    Menu,
}

因为这样可以编译为:

components = {
    Menu: Menu,
}

@Gcaufy
Copy link
Collaborator

Gcaufy commented Mar 15, 2017

@sqaiyan 你说的应该是另外一个问题,刚测试了一下,的确如此,如果直接写component会报Cannot read property 'prefix' of null
刚提交了一个commit修复了这个问题。

@wangzexi
Copy link
Author

@liumin1128 测试过,应该不是大小写的问题。
@sqaiyan 我确实没有把组件包起来,还没来及测试。
@Gcaufy 原来问题出在这里,辛苦了辛苦了。🍭

@Gcaufy
Copy link
Collaborator

Gcaufy commented Mar 15, 2017

@wangzexi
刚才把我的组件从components移动到pages文件夹中,所以我的组件引用变成了
import Test from './../pages/test';

但是经过测试,没有报错, 所以看看是不是是@sqaiyan 说的问题。

@Gcaufy
Copy link
Collaborator

Gcaufy commented May 4, 2017

#123

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants