gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 23:20:24 25 4
gpt4 key购买 nike

我找了半天也没找到解决办法。我是第一次使用 webpack,不是通过 Vue.js 自动化工具的 Laravel 为我设置的。在没有 webpack.config.js 配置文件(零配置模式)的情况下,Webpack 在生产或开发模式下构建得很好,但是当我添加 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 文件之前一切正常——即使是空白,没有配置,我也会收到错误消息。该文件不存在或出现错误。

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

最佳答案

我终于明白了!我希望答案是复杂且难以实现的,考虑到我一直在解决这个问题,但这就像更新我的 Node 和 NPM 版本一样简单。

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

这是相当不科学的,所以我不确定是节点升级还是 NPM 升级有帮助,或者我是否可以更新到较新的版本——但如果其他人遇到问题,尝试更新的 Node 或 NPM 版本。

关于javascript - 仅当 webpack.config.js 存在时,Webpack 构建才会失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50902895/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com