【问题标题】:webpack modules.export not definedwebpack modules.export 未定义
【发布时间】:2017-07-19 20:46:48
【问题描述】:

NPM、Node 和 webpack 版本是

C:\>npm --version
5.3.0

C:\>node --version
v6.10.2

C:\>webpack --version
3.3.0

我已经创建了标准的 scala/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 命令(见图)。但是在运行应用程序时,npm start 声明模块未定义的错误(参考 webpack.config.js 中的 modules.export 语句)

`

在 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

> angular2-webpack@1.0.0 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! angular2-webpack@1.0.0 start: `webpack`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the angular2-webpack@1.0.0 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

【问题讨论】:

  • 仅供参考,nodejs 现在稳定在版本 8,npm 在版本 5,带来了巨大的性能改进:consider upgrading

标签: intellij-idea webpack


【解决方案1】:

您的webpack.config.js 必须以module.exports 而不是modules.export 开头。

它以编程方式表示简单的英语等价物:“此模块导出”。

【讨论】:

  • 谢谢。我会尽快接受答案(必须等待 10 分钟)。现在我面临一个新问题 - throw new Error("'output.filename' is required, either in config file or as --output-filename"); 但我已经在 webpack.config.js 中定义了输出。
  • 很高兴听到这个消息。这确实是另一个问题。也许是因为它没有指定路径?尝试将path: __dirname + "/dist", 添加到output {} 对象(或您想要资产的任何位置,相对于__dirname,这是webpack.config.js 所在的文件夹)。
  • 打开了另一个错误 - 请您在那里回复。我添加了路径,但它仍然不起作用 - stackoverflow.com/questions/45191495/…
猜你喜欢
  • 2021-11-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-19
  • 2015-05-19
  • 2022-01-05
  • 2021-05-11
  • 2018-08-08
相关资源
最近更新 更多