gpt4 book ai didi

javascript - 多米诺 Angular 通用 : Getting Right-hand side of 'instanceof' is not an object

转载 作者:行者123 更新时间:2023-11-30 19:26:00 27 4
gpt4 key购买 nike

我正在使用 angular universal 和 domino 在 express 服务器上“伪造”DOM 服务器端。一切正常,直到 npm cache clean --force 然后 npm install

我收到以下错误:

/path/to/app/src/gui/dist/server/server.js:2378
*/(s),2))[0],l=i[1]),this.engine.listen(this.namespaceId,a,s,l,function(e){var t=e._data||-1;o.factory.scheduleListenerCallback(t,n,e)})}return this.delegate.listen(e,t,n)},t}(h);var g=function(e){function t(t,n,r){return e.call(this,t.body,n,r)||this}return Object(r.c)(t,e),t=Object(r.b)([Object(i.Injectable)(),Object(r.e)(0,Object(i.Inject)(l.DOCUMENT)),Object(r.d)("design:paramtypes",[Object,s.AnimationDriver,s["ɵAnimationStyleNormalizer"]])],t)}(s["ɵAnimationEngine"]);function v(){return Object(s["ɵsupportsWebAnimations"])()?new s["ɵWebAnimationsDriver"]:new s["ɵCssKeyframesDriver"]}function y(){return new s["ɵWebAnimationsStyleNormalizer"]}function b(e,t,n){return new f(e,t,n)}var w=new i.InjectionToken("AnimationModuleType"),_=[{provide:a.AnimationBuilder,useClass:u},{provide:s["ɵAnimationStyleNormalizer"],useFactory:y},{provide:s["ɵAnimationEngine"],useClass:g},{provide:i.RendererFactory2

TypeError: Right-hand side of 'instanceof' is not an object
at bt (/path/to/app/src/gui/dist/server/server.js:2378:180688)
at yt (/path/to/app/src/gui/dist/server/server.js:2378:180563)
at ir (/path/to/app/src/gui/dist/server/server.js:2378:203358)
at We.insertToken (/path/to/app/src/gui/dist/server/server.js:2378:179949)
at /path/to/app/src/gui/dist/server/server.js:2378:183251
at kt (/path/to/app/src/gui/dist/server/server.js:2378:183266)
at Xe (/path/to/app/src/gui/dist/server/server.js:2378:178211)
at Object.parse (/path/to/app/src/gui/dist/server/server.js:2378:177177)
at Object.t.createDocument (/path/to/app/src/gui/dist/server/server.js:2833:9750)
at Object.t.createWindow (/path/to/app/src/gui/dist/server/server.js:2833:10129)

错误发生在domino的HTMLParser.js中,行:2177在以下几行:

doc._appendChild(root);
stack.push(root);
if (fragmentContext instanceof impl.HTMLTemplateElement) {
templateInsertionModes.push(in_template_mode);
}

impl.HTMLTemplateElement 实际上是空的。

我使用 domino 声明的 server.ts 片段是:

// const domino = require('@angular/platform-server/node_modules/domino');
const domino = require('domino');

const template = fs.readFileSync(path.join(process.cwd(), 'dist', 'browser', 'index.html')).toString();
const win = domino.createWindow(template);
global['window'] = win;
global['document'] = win.document;
global['DOMTokenList'] = win.DOMTokenList;
global['Node'] = win.Node;
global['Text'] = win.Text;
global['jQuery'] = {};
// global['$'] = require('jquery');
// global['window.$'] = require('jquery');
global['HTMLElement'] = win.HTMLElement;
global['Materialize'] = win.Materialize;
global['navigator'] = win.navigator;

对这个问题有什么建议吗?

最佳答案

我发现问题的根源是由于将“生产”模式设置为 webpack。事实上,出于性能原因,我在 webpack.server.config.js

中进行了设置
module.exports = {
mode: 'production',
...
}

此模式会导致多米诺骨牌发生意外行为。设置 mode: 'none' 解决了这个问题。

关于javascript - 多米诺 Angular 通用 : Getting Right-hand side of 'instanceof' is not an object,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56903846/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com