2017-08-24 74 views
0

當我運行命令webpack -p時,我得到了errno 2。errno 2在webpack -p

當我只運行webpack時,一切正常。

所以我有下面的命令在我的package.json:

"dev": "rimraf dist && NODE_ENV=development webpack", 
"build": "rimraf dist && NODE_ENV=production webpack -p", 

而且有我的webpack.config.js此配置:

const path = require('path'); 
const webpack = require('webpack'); 
const SassLintPlugin = require('sasslint-webpack-plugin'); 
const ExtractTextPlugin = require('extract-text-webpack-plugin'); 
const HtmlWebpackPlugin = require('html-webpack-plugin'); 
const CompressionPlugin = require('compression-webpack-plugin'); 
const CopyWebpackPlugin = require('copy-webpack-plugin'); 

const extractSass = new ExtractTextPlugin({ 
    filename: '[name].css', 
    disable: process.env.NODE_ENV === 'development', 
}); 

const plugins = [ 
    new webpack.DefinePlugin({ 
    'process.env': { 
     NODE_ENV: JSON.stringify(process.env.NODE_ENV), 
     STAGE: JSON.stringify(process.env.STAGE), 
    }, 
    }), 
    new CopyWebpackPlugin([ 
    { from: path.join(__dirname, 'app/js/pwa/manifest.json'), to: path.join(__dirname, 'dist') }, 
    { from: path.join(__dirname, 'app/js/pwa/sw.js'), to: path.join(__dirname, 'dist') }, 
    { from: path.join(__dirname, 'app/js/pushstream/pushstream.js'), to: path.join(__dirname, 'dist') }, 
    { from: path.join(__dirname, 'app/img/favicon.png'), to: path.join(__dirname, 'dist') }, 
    { from: path.join(__dirname, 'app/img/tecnoseniorIcon.png'), to: path.join(__dirname, 'dist') }, 
    ]), 
    new SassLintPlugin({ 
    configFile: '.sass-lint.yml', 
    context: [path.resolve(__dirname, './app/')], 
    ignoreFiles: [], 
    ignorePlugins: [], 
    glob: '**/*.s?(a|c)ss', 
    quiet: false, 
    failOnWarning: false, 
    failOnError: true, 
    testing: false, 
    }), 
    extractSass, 
    new HtmlWebpackPlugin({ 
    title: 'Contactto Anywhere', 
    template: 'app/index-template.html', 
    // minify: { 
    // collapseWhitespace: process.env.NODE_ENV === 'production', 
    // }, 
    }), 
]; 

if (process.env.NODE_ENV === 'development') { 
    plugins.push(new webpack.HotModuleReplacementPlugin()); 
} 

if (process.env.NODE_ENV === 'production') { 
    plugins.push(new CompressionPlugin({ 
    asset: '[path].gz[query]', 
    algorithm: 'gzip', 
    test: /\.js$|\.css$|\.html$/, 
    threshold: 10240, 
    minRatio: 0.8, 
    })); 
    plugins.push(new webpack.optimize.ModuleConcatenationPlugin()); 
} 

module.exports = { 
    entry: process.env.NODE_ENV === 'development' ? 
    { 
    main: [ 
     'webpack-hot-middleware/client?reload=true', 
     'react-hot-loader/patch', 
     './app/index.jsx', 
    ], 
    pwa: './app/js/pwa/mainPwa.js', 
    } 
    : 
    { 
    main: './app/index.jsx', 
    pwa: './app/js/pwa/mainPwa.js', 
    }, 
    output: { 
    filename: '[name].js', 
    path: path.resolve(__dirname, 'dist'), 
    publicPath: '/', 
    }, 
    target: 'web', 
    devtool: process.env.NODE_ENV === 'development' ? 'inline-source-map' : 'source-map', 

    module: { 
    rules: [ 
     { 
     test: /\.jsx?$/, 
     include: path.resolve(__dirname, './app/'), 
     exclude: /node_modules/, 
     loader: 'babel-loader', 
     }, 
     { 
     test: /\.scss$/, 
     include: path.resolve(__dirname, './app/'), 
     loader: extractSass.extract({ 
      use: [ 
      { loader: 'css-loader?modules&localIdentName=[name]__[local]___[hash:base64:5]' }, 
      { loader: 'sass-loader' }, 
      ], 
      // use style-loader in development 
      fallback: 'style-loader', 
     }), 
     exclude: /node_modules/, 
     }, 
     { 
     test: /\.(eot|ttf|woff|woff2)$/, 
     loader: 'file-loader?name=fonts/[name].[ext]', 
     }, 
     { 
     test: /\.(png|svg|jpg|webp)$/, 
     use: { 
      loader: 'file-loader', 
     }, 
     }, 
    ], 
    }, 
    resolve: { 
    extensions: ['.js', '.jsx'], 
    modules: [path.resolve(__dirname, 'node_modules')], 
    }, 
    plugins, 
}; 

的的WebPack -p正在几几天前,但現在它給這個錯誤。 我沒有改變我的webpack.config.js很長一段時間。

日誌文件:

0 info it worked if it ends with ok 
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'run', 'build' ] 
2 info using [email protected] 
3 info using [email protected] 
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ] 
5 info lifecycle [email protected]~prebuild: [email protected] 
6 info lifecycle [email protected]~build: [email protected] 
7 verbose lifecycle [email protected]~build: unsafe-perm in lifecycle true 
8 verbose lifecycle [email protected]~build: PATH: /usr/local/lib/node_modules/npm/bin/node-gyp-bin:/Users/alexfqc/Documents/contactto-master-frontend/node_modules/.bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/alexfqc/Library/Android/sdk/tools:/Users/alexfqc/Library/Android/sdk/platform-tools:/Users/alexfqc/mongodb-osx-x86_64-enterprise-3.4.6/bin 
9 verbose lifecycle [email protected]~build: CWD: /Users/alexfqc/Documents/contactto-master-frontend 
10 silly lifecycle [email protected]~build: Args: [ '-c', 'rimraf dist && NODE_ENV=production webpack -p' ] 
11 silly lifecycle [email protected]~build: Returned: code: 2 signal: null 
12 info lifecycle [email protected]~build: Failed to exec build script 
13 verbose stack Error: [email protected] build: `rimraf dist && NODE_ENV=production webpack -p` 
13 verbose stack Exit status 2 
13 verbose stack  at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/lifecycle.js:289:16) 
13 verbose stack  at emitTwo (events.js:125:13) 
13 verbose stack  at EventEmitter.emit (events.js:213:7) 
13 verbose stack  at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/spawn.js:40:14) 
13 verbose stack  at emitTwo (events.js:125:13) 
13 verbose stack  at ChildProcess.emit (events.js:213:7) 
13 verbose stack  at maybeClose (internal/child_process.js:887:16) 
13 verbose stack  at Process.ChildProcess._handle.onexit (internal/child_process.js:208:5) 
14 verbose pkgid [email protected] 
15 verbose cwd /Users/alexfqc/Documents/contactto-master-frontend 
16 verbose Darwin 16.7.0 
17 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "build" 
18 verbose node v8.0.0 
19 verbose npm v5.3.0 
20 error code ELIFECYCLE 
21 error errno 2 
22 error co[email protected] build: `rimraf dist && NODE_ENV=production webpack -p` 
22 error Exit status 2 
23 error Failed at the [email protected] build script. 
23 error This is probably not a problem with npm. There is likely additional logging output above. 
24 verbose exit [ 2, true ] 

我不知道發生了什麼,誰能幫助我?

在此先感謝。

回答

0

我發現了錯誤,

我試圖使用異步並等待沒有預設。