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

art-template runtime window未定义 #553

Closed
wangzhigang opened this issue Sep 10, 2018 · 6 comments
Closed

art-template runtime window未定义 #553

wangzhigang opened this issue Sep 10, 2018 · 6 comments

Comments

@wangzhigang
Copy link

var runtime = Object.create(detectNode ? global : window);

报错 window 未定义

建议安装@fedor/global
var window = require('@fedor/global');
var runtime = Object.create(detectNode ? global : window); 修复此问题

@aui
Copy link
Owner

aui commented Sep 10, 2018

什么情况会报错?

@jeiizou
Copy link

jeiizou commented Sep 13, 2018

重新 npm install 以后就一直报这个错误

@aui
Copy link
Owner

aui commented Sep 14, 2018

给一下有助于重现的信息吧,例如 nodejs 和 npm 版本

@lnyielea
Copy link

ERROR in Error: /Users/linyi/work/company/sqjh/test/src/pages/index/index.art:769
var runtime = Object.create(detectNode ? global : window);
^
ReferenceError: window is not defined

  • index.art:769 Object.
    /Users/linyi/work/company/sqjh/test/src/pages/index/index.art:769:51

  • index.art:863 Object../node_modules/art-template/lib/compile/runtime.js
    /Users/linyi/work/company/sqjh/test/src/pages/index/index.art:863:30

  • index.art:684 webpack_require
    /Users/linyi/work/company/sqjh/test/src/pages/index/index.art:684:30

  • index.art:61 fn
    /Users/linyi/work/company/sqjh/test/src/pages/index/index.art:61:20

  • index.art:877 Object../node_modules/art-template/lib/runtime.js
    /Users/linyi/work/company/sqjh/test/src/pages/index/index.art:877:18

  • index.art:684 webpack_require
    /Users/linyi/work/company/sqjh/test/src/pages/index/index.art:684:30

  • index.art:61 fn
    /Users/linyi/work/company/sqjh/test/src/pages/index/index.art:61:20

  • index.art:901 Object../node_modules/html-webpack-plugin/lib/loader.js!./src/pages/index/index.art
    /Users/linyi/work/company/sqjh/test/src/pages/index/index.art:901:16

  • index.art:684 webpack_require
    /Users/linyi/work/company/sqjh/test/src/pages/index/index.art:684:30

  • index.art:751
    /Users/linyi/work/company/sqjh/test/src/pages/index/index.art:751:114
    node v8.2.1 v10.1.0 v10.10.0都会这样。npm 5

@zhihuilai
Copy link

zhihuilai commented Sep 23, 2018

应该是 detect-node 的问题:
iliakan/detect-node#12

@zhihuilai
Copy link

zhihuilai commented Sep 23, 2018

detect-node 通过以下语句判断是否在 node 环境中:

module.exports = Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]';

以上语句简单理解为 process.toString();

我在 HtmlWebpackPlugin 中使用 art-template,process.toString 是 [object object],但在 node 中直接执行 process.toString() 是 [object process],不确定是不是 HtmlWebpackPlugin 应该背锅,有可能是其它代码引起的,但可以确认 detect-node 在某些情况下会判断错误。

aui added a commit that referenced this issue Sep 25, 2018
@aui aui closed this as completed Sep 26, 2018
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

5 participants