2017-09-19 121 views
1

我正在使用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.

+1

刪除你的'node_nodules'文件夾並重新安裝,看起來你有一個損壞的軟件包。 – James

+0

@詹姆斯我刪除了我的node_nodules文件夾,並一直工作,直到我下載了另一個包前。 npm install --save @ types/mongoose。在此之後,我得到了同樣的錯誤。我沒有再次刪除文件夾,而是運行了npm install並修復了它。爲什麼我需要每次都這樣做? –

+0

你使用的是'webpack-dev-server'還是'webpack -w'?有時他們可能會過早地重新編譯,讓事情處於滑稽狀態。 – James

回答

0

角CLI內部使用的軟件包並進行安裝,所以你不會看到他們的package.json文件,以便刪除您wepback配置文件。如果你想完全控制軟件包使用彈出,你會看到webpack配置文件,但你會鬆開ng - 任何命令。並重新檢查你是如何將jquery添加到你的項目中的。