我正在使用Angular 4的一些样板代码,并且遇到问题。它工作正常,直到我从npm下载另一个包。我得到以下错误,并且ng服务命令不再起作用。该项目已经安装了jquery,所以错误对我来说没有意义。没有webpack.config.js文件,所以我添加了下面的代码。任何帮助,将不胜感激。安装包后Webpack无法编译错误
webpack.config.js文件
var webpack = require('webpack');
var config = {
plugins: [
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery"
})
]
};
module.exports = config;
错误
WARNING in ./~/jsdom/lib/jsdom/utils.js 216:21-40 Critical dependency: the request of a dependency is an expression
WARNING in ./~/jsdom/lib/jsdom/living/xmlhttprequest.js 20:23-30 Critical dependency: require function is used in a way in which dependencies cannot be statically extracted
WARNING in ./~/ajv/lib/async.js 96:20-33 Critical dependency: the request of a dependency is an expression
WARNING in ./~/ajv/lib/async.js 119:15-28 Critical dependency: the request of a dependency is an expression
WARNING in ./~/ajv/lib/compile/index.js 13:21-34 Critical dependency: the request of a dependency is an expression
ERROR in ./~/jquery/lib/node-jquery.js Module not found: Error: Can't resolve 'xmlhttprequest' in 'E:\WebstormProjects\innovation-node-server-2.0\node_modules\jquery\lib' @ ./~/jquery/lib/node-jquery.js 8:28-53 @ ./src/lib.ts @ ./src/main.ts @ multi webpack-dev-server/client? http://localhost:4200 ./src/main.ts
ERROR in ./~/jquery/lib/node-jquery.js Module not found: Error: Can't resolve 'location' in 'E:\WebstormProjects\innovation-node-server-2.0\node_modules\jquery\lib' @ ./~/jquery/lib/node-jquery.js 13:24-43 @ ./src/lib.ts @ ./src/main.ts @ multi webpack-dev-server/client? http://localhost:4200 ./src/main.ts
ERROR in ./~/jquery/lib/node-jquery.js Module not found: Error: Can't resolve 'navigator' in 'E:\WebstormProjects\innovation-node-server-2.0\node_modules\jquery\lib' @ ./~/jquery/lib/node-jquery.js 17:25-45 @ ./src/lib.ts @ ./src/main.ts @ multi webpack-dev-server/client? http://localhost:4200 ./src/main.ts
ERROR in ./~/jsdom/lib/jsdom/living/xmlhttprequest.js Module not found: Error: Can't resolve 'child_process' in 'E:\WebstormProjects\innovation-node-server-2.0\node_modules\jsdom\lib\jsdom\living' @ ./~/jsdom/lib/jsdom/living/xmlhttprequest.js 4:18-42 @ ./~/jsdom/lib/jsdom/browser/Window.js @ ./~/jsdom/lib/jsdom.js @ ./~/jquery/lib/node-jquery.js @ ./src/lib.ts @ ./src/main.ts @ multi webpack-dev-server/client? http://localhost:4200 ./src/main.ts webpack: Failed to compile.
删除你的'node_nodules'文件夹并重新安装,看起来你有一个损坏的软件包。 – James
@詹姆斯我删除了我的node_nodules文件夹,并一直工作,直到我下载了另一个包前。 npm install --save @ types/mongoose。在此之后,我得到了同样的错误。我没有再次删除文件夹,而是运行了npm install并修复了它。为什么我需要每次都这样做? –
你使用的是'webpack-dev-server'还是'webpack -w'?有时他们可能会过早地重新编译,让事情处于滑稽状态。 – James