简体   繁体   中英

Webpack build fails only when webpack.config.js exists

I've searched this to death and haven't found a solution. I'm using webpack for the first time not set up for me via Laravel of Vue.js automated tools. Webpack builds just fine in production or development modes without the webpack.config.js config file present (zero-config mode), but throws a very unhelpful error when I add in the webpack.config.js file to set up the Babel loader. I'm on Windows, if that affects anything.

My 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'
        }]
    }
}

unhelpful debug log:

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 ]

Other setup is standard: There is the recommended src/ folder containing index.js entry point, and a dist/ folder to receive the bundled main.js file. It all works until I create the webpack.config.js file--even blank, with no configuration, I get an error. The file cannot exist or I get an error.

Thanks for any help and guidance anyone can give!

At last, I got it figured out! I wish the answer were complex and difficult to implement, given all the time I've put into this issue, but it was as simple as updating my Node and NPM versions.

I updated NPM from 5.8.0 to 6.1.0; I updated Node from 8.9.3 to the most recent, 10.4.1. Webpack does not need specified entry and output settings in the config file.

This was fairly unscientific, so I'm not sure if it was the Node upgrade or the NPM upgrade that helped, or if I could have updated to a less recent version of either--but if anyone else is having trouble, try a more recent Node or NPM version.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM