操作系统:Windows 10 Pro
NPM版本:3.8.6
因此,我尝试使用npm build
构建项目但未生成项目构建输出文件夹,并生成以下错误日志:
0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm- cli.js',
1 verbose cli 'run',
1 verbose cli 'build' ]
2 info using npm@3.8.6
3 info using node@v6.1.0
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle learn-redux@1.0.0~prebuild: learn-redux@1.0.0
6 silly lifecycle learn-redux@1.0.0~prebuild: no script for prebuild, continuing
7 info lifecycle learn-redux@1.0.0~build: learn-redux@1.0.0
8 verbose lifecycle learn-redux@1.0.0~build: unsafe-perm in lifecycle true
9 verbose lifecycle learn-redux@1.0.0~build: PATH: C:\Program Files\nodejs\node_modules\npm\bin\node-gyp-bin;C:\Users\d0475\Documents\Projects\learn-redux\node_modules\.bin;C:\Program Files\nodejs;C:\Users\d0475\Documents\Cmder\bin;C:\Program Files\Git\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Git\share\vim\vim74;C:\Users\d0475\Documents\Cmder\vendor\conemu-maximus5\ConEmu\Scripts;C:\Users\d0475\Documents\Cmder\vendor\conemu-maximus5;C:\Users\d0475\Documents\Cmder\vendor\conemu-maximus5\ConEmu;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\GNU\GnuPG\pub;C:\Program Files\Git\cmd;C:\Program Files\nodejs\;C:\Program Files\Calibre2\;C:\Users\d0475\AppData\Local\Microsoft\WindowsApps;C:\Users\d0475\AppData\Roaming\npm;C:\Program Files (x86)\Microsoft VS Code\bin;C:\Users\d0475\AppData\Local\Microsoft\WindowsApps;;C:\Users\d0475\Documents\Cmder
10 verbose lifecycle learn-redux@1.0.0~build: CWD: C:\Users\d0475\Documents\Projects\learn-redux
11 silly lifecycle learn-redux@1.0.0~build: Args: [ '/d /s /c', 'npm run clean && npm run build:webpack' ]
12 silly lifecycle learn-redux@1.0.0~build: Returned: code: 1 signal: null
13 info lifecycle learn-redux@1.0.0~build: Failed to exec build script
14 verbose stack Error: learn-redux@1.0.0 build: `npm run clean && npm run build:webpack`
14 verbose stack Exit status 1
14 verbose stack at EventEmitter.<anonymous> (C:\Program Files\nodejs\node_modules\npm\lib\utils\lifecycle.js:239:16)
14 verbose stack at emitTwo (events.js:106:13)
14 verbose stack at EventEmitter.emit (events.js:191:7)
14 verbose stack at ChildProcess.<anonymous> (C:\Program Files\nodejs\node_modules\npm\lib\utils\spawn.js:24:14)
14 verbose stack at emitTwo (events.js:106:13)
14 verbose stack at ChildProcess.emit (events.js:191:7)
14 verbose stack at maybeClose (internal/child_process.js:850:16)
14 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:215:5)
15 verbose pkgid learn-redux@1.0.0
16 verbose cwd C:\Users\d0475\Documents\Projects\learn-redux
17 error Windows_NT 10.0.14986
18 error argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "build"
19 error node v6.1.0
20 error npm v3.8.6
21 error code ELIFECYCLE
22 error learn-redux@1.0.0 build: `npm run clean && npm run build:webpack`
22 error Exit status 1
23 error Failed at the learn-redux@1.0.0 build script 'npm run clean && npm run build:webpack'.
23 error Make sure you have the latest version of node.js and npm installed.
23 error If you do, this is most likely a problem with the learn-redux package,
23 error not with npm itself.
23 error Tell the author that this fails on your system:
23 error npm run clean && npm run build:webpack
23 error You can get information on how to open an issue for this project with:
23 error npm bugs learn-redux
23 error Or if that isn't available, you can get their info via:
23 error npm owner ls learn-redux
23 error There is likely additional logging output above.
24 verbose exit [ 1, true ]
&#13;
我的package.json内容如下:
"scripts": {
"build:webpack": "NODE_ENV=production webpack --config webpack.config.prod.js",
"build": "npm run clean && npm run build:webpack",
"test": "NODE_ENV=production mocha './tests/**/*.spec.js' --compilers js:babel-core/register",
"clean": "rimraf dist",
"start": "node devServer.js"
},
&#13;
我的webpack.config.prod.js
内容如下:
var path = require('path');
var webpack = require('webpack');
module.exports = {
devtool: 'source-map',
entry: [
'./client/reduxstagram'
],
output: {
path: path.join(__dirname, 'dist'),
filename: 'bundle.js',
publicPath: '/static/'
},
plugins: [
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': "'production'"
}
}),
new webpack.optimize.UglifyJsPlugin({
compressor: {
warnings: false
}
})
],
module: {
loaders: [
// js
{
test: /\.js$/,
loaders: ['babel'],
include: path.join(__dirname, 'client')
},
// CSS
{
test: /\.styl$/,
include: path.join(__dirname, 'client'),
loader: 'style-loader!css-loader!stylus-loader'
}
]
}
};
&#13;
这是什么问题?
答案 0 :(得分:0)
通过更改以下问题解决了问题:
"build:webpack": "NODE_ENV=production webpack --config webpack.config.prod.js",
到
"build:webpack": "set NODE_ENV=production && webpack --config webpack.config.prod.js",
答案 1 :(得分:0)
我遇到了同样的问题,有时与代码无关。
有时将“main.js”和“app.js”文件放在项目的“src”文件夹中!
文件“main.js”被复制到文件夹“src”中,在同一个文件夹中是子文件夹“components”“app.js”
那是我问题的解决方案!