我正在使用 Angular 4 +webpack。我在 webpack.config.vendor.js 的 nonTreeShakableModules const 中添加了一个 jQuery 插件:
const path = require('path');
const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const merge = require('webpack-merge');
const treeShakableModules = [
'@angular/animations',
'@angular/common',
'@angular/compiler',
'@angular/core',
'@angular/forms',
'@angular/http',
'@angular/platform-browser',
'@angular/platform-browser-dynamic',
'@angular/router',
'font-awesome/css/font-awesome.css',
'zone.js',
];
const nonTreeShakableModules = [
'bootstrap',
'bootstrap/dist/css/bootstrap.css',
'es6-promise',
'es6-shim',
'event-source-polyfill',
'jquery',
'virtual-keyboard' //HERE
];
启动应用程序时出现此错误:
NodeInvocationException:预渲染失败,因为错误:错误: jQuery 需要一个带有文档的窗口
如果我刷新页面 2-3 次,错误就消失了。谢谢你的帮助!