仅当webpack.config.js存在时,Webpack构建才会失败

时间:2018-06-18 04:59:48

标签: javascript webpack

我搜索过这个死亡并没有找到解决方案。我第一次使用webpack通过Laravel of Vue.js自动化工具没有为我设置。 Webpack在生产或开发模式下构建得很好,没有webpack.config.js配置文件(零配置模式),但是当我添加webpack.config.js文件来设置Babel加载器时,会抛出一个非常无用的错误。我在Windows上,如果这会影响任何事情。

我的package.json:

{
  "name": "portfolio_update",
  "version": "1.0.0",
  "description": "Port to Vue.js",
  "main": "src/index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "build": "webpack --mode production",
    "dev": "webpack --mode development",
    "watch": "webpack --watch --mode production"
  },
  "author": "Jake Runge",
  "license": "ISC",
  "devDependencies": {
    "babel-core": "^6.26.3",
    "babel-loader": "^7.1.4",
    "babel-preset-env": "^1.7.0",
    "webpack": "^4.12.0",
    "webpack-cli": "^3.0.8"
  },
  "dependencies": {
    "jquery": "^3.3.1"
  }
}

webpack.config.js:

module.exports = {
    module: {
        rules: [{
            test: /\.js$/,
            exclude: /node_modules/,
            loader: 'babel-loader'
        }]
    }
}

无用的调试日志:

0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli   'C:\\Users\\jwrun\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   'run',
1 verbose cli   'dev' ]
2 info using npm@5.8.0
3 info using node@v8.9.3
4 verbose run-script [ 'predev', 'dev', 'postdev' ]
5 info lifecycle portfolio_update@1.0.0~predev: portfolio_update@1.0.0
6 info lifecycle portfolio_update@1.0.0~dev: portfolio_update@1.0.0
7 verbose lifecycle portfolio_update@1.0.0~dev: unsafe-perm in lifecycle true
8 verbose lifecycle portfolio_update@1.0.0~dev: PATH: C:\Users\jwrun\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\Bitnami\wampstack-7.1.12-0\apache2\htdocs\Portfolio_update\node_modules\.bin;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files (x86)\Common Files\Intel\Shared Libraries\redist\intel64\compiler;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\nodejs\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\PuTTY\;C:\Bitnami\wampstack-7.1.12-0\php;C:\ProgramData\ComposerSetup\bin;C:\HashiCorp\Vagrant\bin;C:\Program Files\Git\cmd;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\WINDOWS\System32\OpenSSH\;C:\Users\jwrun\AppData\Local\Programs\Python\Python36-32\Scripts\;C:\Users\jwrun\AppData\Local\Programs\Python\Python36-32\;C:\Users\jwrun\AppData\Local\Microsoft\WindowsApps;C:\Users\jwrun\AppData\Local\GitHubDesktop\bin;C:\Users\jwrun\AppData\Roaming\npm;C:\Users\jwrun\AppData\Local\Microsoft\WindowsApps;C:\Users\jwrun\AppData\Roaming\Composer\vendor\bin;C:\Program Files\Microsoft VS Code\bin;C:\Program Files\MongoDB\Server\3.6\bin
9 verbose lifecycle portfolio_update@1.0.0~dev: CWD: C:\Bitnami\wampstack-7.1.12-0\apache2\htdocs\Portfolio_update
10 silly lifecycle portfolio_update@1.0.0~dev: Args: [ '/d /s /c', 'webpack --mode development' ]
11 silly lifecycle portfolio_update@1.0.0~dev: Returned: code: 1  signal: null
12 info lifecycle portfolio_update@1.0.0~dev: Failed to exec dev script
13 verbose stack Error: portfolio_update@1.0.0 dev: `webpack --mode development`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (C:\Users\jwrun\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\index.js:283:16)
13 verbose stack     at emitTwo (events.js:126:13)
13 verbose stack     at EventEmitter.emit (events.js:214:7)
13 verbose stack     at ChildProcess.<anonymous> (C:\Users\jwrun\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack     at emitTwo (events.js:126:13)
13 verbose stack     at ChildProcess.emit (events.js:214:7)
13 verbose stack     at maybeClose (internal/child_process.js:925:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
14 verbose pkgid portfolio_update@1.0.0
15 verbose cwd C:\Bitnami\wampstack-7.1.12-0\apache2\htdocs\Portfolio_update
16 verbose Windows_NT 10.0.17134
17 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\jwrun\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "run" "dev"
18 verbose node v8.9.3
19 verbose npm  v5.8.0
20 error code ELIFECYCLE
21 error errno 1
22 error portfolio_update@1.0.0 dev: `webpack --mode development`
22 error Exit status 1
23 error Failed at the portfolio_update@1.0.0 dev script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

其他设置是标准的:推荐的src/文件夹包含index.js入口点,dist/文件夹用于接收捆绑的main.js文件。这一切都有效,直到我创建webpack.config.js文件 - 即使是空白,没有配置,我收到错误。该文件不存在或我收到错误。

感谢任何人提供的任何帮助和指导!

1 个答案:

答案 0 :(得分:1)

最后,我弄清楚了!我希望答案很复杂,难以实现,因为我已经把这个问题放在了这个问题上,但它就像更新我的Node和NPM版本一样简单。

我将NPM从5.8.0更新到6.1.0;我将Node从8.9.3更新到最新的10.4.1。 Webpack不需要在配置文件中指定输入和输出设置。

这是相当不科学的,所以我不确定它是否有节点升级或NPM升级有帮助,或者我是否可以更新到较新版本的任何一个 - 但如果其他人遇到麻烦,尝试更新的Node或NPM版本。