2017-07-19 63 views
1

NPM,節點的WebPack版本的WebPack modules.export沒有定義

C:\>npm --version 
5.3.0 

C:\>node --version 
v6.10.2 

C:\>webpack --version 
3.3.0 

我創建標準斯卡拉/ Play2項目。其中,我在app/ts文件夾中添加了4個Typescript文件(Angular)。我也創建了以下的WebPack配置文件

modules.export = { 
    entry: [ 
     '/ts/main.ts', 
     '/ts/vendor.ts' 
    ], 
    output:{ 
     filename:'[name].bundle.js' 
    }, 
    rules: 
     { 
      test:'/\.ts$/', 
      loader:'awesome-typescript-loader' 
     } 
} 

爲了使事情運行(下載的依賴關係和執行的WebPack到TS轉換爲JS),我編輯的遊戲配置,並在「推出前」部分增加了兩個NPM命令(見圖)。但在運行的應用程序,故宮開始宣告錯誤模塊沒有定義(指的modules.export在webpack.config.js語句)

`enter image description here

在的IntelliJ控制檯

"C:\Program Files\JetBrains\IntelliJ IDEA 2017.1.3\bin\runnerw.exe" "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" run start --scripts-prepend-node-path=auto 

> [email protected] start C:\Users\Manu\Documents\manu\programs\scala\play_programs\temp\app 
> webpack 

C:\Users\Manu\Documents\manu\programs\scala\play_programs\temp\app\webpack.config.js:3 
modules.export = { 
^ 

ReferenceError: modules is not defined 
    at Object.<anonymous> (C:\Users\Manu\Documents\manu\programs\scala\play_programs\temp\app\webpack.config.js:3:1) 
    at Module._compile (module.js:570:32) 
    at Object.Module._extensions..js (module.js:579:10) 
    at Module.load (module.js:487:32) 
    at tryModuleLoad (module.js:446:12) 
    at Function.Module._load (module.js:438:3) 
    at Module.require (module.js:497:17) 
    at require (internal/module.js:20:19) 
    at requireConfig (C:\Users\Manu\Documents\manu\programs\scala\play_programs\temp\app\node_modules\webpack\bin\convert-argv.js:96:18) 
    at C:\Users\Manu\Documents\manu\programs\scala\play_programs\temp\app\node_modules\webpack\bin\convert-argv.js:109:17 

npm ERR! Windows_NT 10.0.14393 
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "start" "--scripts-prepend-node-path=auto" 
npm ERR! node v6.10.2 
npm ERR! npm v3.10.10 
npm ERR! code ELIFECYCLE 
npm ERR! [email protected] start: `webpack` 
npm ERR! Exit status 1 
npm ERR! 
npm ERR! Failed at the [email protected] start script 'webpack'. 
npm ERR! Make sure you have the latest version of node.js and npm installed. 
npm ERR! If you do, this is most likely a problem with the angular2-webpack package, 
npm ERR! not with npm itself. 
npm ERR! Tell the author that this fails on your system: 
npm ERR!  webpack 
npm ERR! You can get information on how to open an issue for this project with: 
npm ERR!  npm bugs angular2-webpack 
npm ERR! Or if that isn't available, you can get their info via: 
npm ERR!  npm owner ls angular2-webpack 
npm ERR! There is likely additional logging output above. 

npm ERR! Please include the following file with any support request: 
npm ERR!  C:\Users\Manu\Documents\manu\programs\scala\play_programs\temp\app\npm-debug.log 

Process finished with exit code 1 
+0

僅供參考nodejs現在穩定在版本8,npm在版本5時帶來了很大的性能改進:[考慮升級](https://nodejs.org/)。 – msanford

回答

1

webpack.config.js必須以module.exports而不是modules.export開頭。

它以編程方式表示簡單的英語等效:「此模塊出口」。

+0

謝謝。我會很快接受答案(必須等待10分鐘)。現在我面臨一個新問題 - '拋出新的錯誤(「'輸出文件名'是必需的,無論是在配置文件或作爲 - 輸出文件名」);'但我已經定義輸出在webpack.config.js已經。 –

+0

很高興聽到它。這確實是另一個問題。也許是因爲它沒有指定路徑?嘗試在'output {}'對象(或者你想要你的資產的任何地方,相對於'__dirname',這是'webpack.config.js'文件夾所在的位置)添加'path:__dirname +'/ dist','。 – msanford

+0

打開了另一個錯誤 - 請你回覆。我添加了路徑,但它仍然不起作用 - https://stackoverflow.com/questions/45191495/webpack-doesnt-recognise-output-file-name –