2016-08-03 83 views
2

清除node_modules文件夾並執行乾淨npm build並運行webpack後,遇到以下錯誤。清理node_modules文件夾後webpack babel生成錯誤

有人可以幫助我瞭解我得到的錯誤嗎?即時通訊新的webpack。

下面的代碼片段是我的webpack.config

var path = require('path'); 
 
var webpack = require('webpack'); 
 

 
var config = { 
 
    devtool: 'cheap-module-eval-source-map', 
 
    entry: [ 
 
    'webpack-hot-middleware/client', 
 
    './app/main' 
 
    ], 
 
    output: { 
 
    path: path.join(__dirname, 'public', 'js'), 
 
    filename: 'bundle.js', 
 
    publicPath: '/js' 
 
    }, 
 
    plugins: [ 
 
    new webpack.HotModuleReplacementPlugin(), 
 
    new webpack.NoErrorsPlugin(), 
 
    new webpack.optimize.OccurenceOrderPlugin(), 
 
    new webpack.DefinePlugin({ 
 
     'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV) 
 
    }) 
 
    ], 
 
    module: { 
 
    loaders: [ 
 
     { 
 
     test: /\.js$/, 
 
     exclude: /node_modules/, 
 
     loader: 'babel', 
 
     query: { 
 
      plugins: [ 
 
      ['react-transform', { 
 
       transforms: [ 
 
       { 
 
        transform: 'react-transform-hmr', 
 
        imports: ['react'], 
 
        locals: ['module'] 
 
       }, { 
 
        transform: 'react-transform-catch-errors', 
 
        imports: ['react', 'redbox-react'] 
 
       } 
 
       ] 
 
      }] 
 
      ], 
 
      presets: ['react', 'es2015', 'stage-1'] 
 
     } 
 
     } 
 
    ] 
 
    }, 
 
    resolve: { 
 
    extensions: ['', '.js', '.jsx', 'css', 'scss'] 
 
    }, 
 
};

ERROR in ./app/components/App.js Module build failed: TypeError: /Users/ericlin/projects/360/app/components/App.js: Property id of VariableDeclarator expected node to be of a type ["LVal"] but instead got "CallExpression" at Object.validate (/Users/ericlin/projects/360/node_modules/babel-types/lib/definitions/index.js:109:13) at Object.validate (/Users/ericlin/projects/360/node_modules/babel-types/lib/index.js:541:9) at NodePath._replaceWith (/Users/ericlin/projects/360/node_modules/babel-traverse/lib/path/replacement.js:208:7) at NodePath.replaceWith (/Users/ericlin/projects/360/node_modules/babel-traverse/lib/path/replacement.js:186:8) at RewireState.Identifier (/Users/ericlin/projects/360/node_modules/babel-plugin-rewire/lib/babel-plugin-rewire.js:176:10) at NodePath._call (/Users/ericlin/projects/360/node_modules/babel-traverse/lib/path/context.js:76:18) at NodePath.call (/Users/ericlin/projects/360/node_modules/babel-traverse/lib/path/context.js:48:17) at NodePath.visit (/Users/ericlin/projects/360/node_modules/babel-traverse/lib/path/context.js:106:12) at TraversalContext.visitQueue (/Users/ericlin/projects/360/node_modules/babel-traverse/lib/context.js:167:16) at TraversalContext.visitSingle (/Users/ericlin/projects/360/node_modules/babel-traverse/lib/context.js:118:19) at TraversalContext.visit (/Users/ericlin/projects/360/node_modules/babel-traverse/lib/context.js:211:19) at Function.traverse.node (/Users/ericlin/projects/360/node_modules/babel-traverse/lib/index.js:161:17) at NodePath.visit (/Users/ericlin/projects/360/node_modules/babel-traverse/lib/path/context.js:116:19) at TraversalContext.visitQueue (/Users/ericlin/projects/360/node_modules/babel-traverse/lib/context.js:167:16) at TraversalContext.visitMultiple (/Users/ericlin/projects/360/node_modules/babel-traverse/lib/context.js:113:17) at TraversalContext.visit (/Users/ericlin/projects/360/node_modules/babel-traverse/lib/context.js:209:19) at Function.traverse.node (/Users/ericlin/projects/360/node_modules/babel-traverse/lib/index.js:161:17) at NodePath.visit (/Users/ericlin/projects/360/node_modules/babel-traverse/lib/path/context.js:116:19) at TraversalContext.visitQueue (/Users/ericlin/projects/360/node_modules/babel-traverse/lib/context.js:167:16) at TraversalContext.visitMultiple (/Users/ericlin/projects/360/node_modules/babel-traverse/lib/context.js:113:17) at TraversalContext.visit (/Users/ericlin/projects/360/node_modules/babel-traverse/lib/context.js:209:19) at Function.traverse.node (/Users/ericlin/projects/360/node_modules/babel-traverse/lib/index.js:161:17) at traverse (/Users/ericlin/projects/360/node_modules/babel-traverse/lib/index.js:83:12) at NodePath.traverse (/Users/ericlin/projects/360/node_modules/babel-traverse/lib/path/index.js:147:25) at PluginPass.exit (/Users/ericlin/projects/360/node_modules/babel-plugin-rewire/lib/babel-plugin-rewire.js:199:11) at newFn (/Users/ericlin/projects/360/node_modules/babel-traverse/lib/visitors.js:301:19) at NodePath._call (/Users/ericlin/projects/360/node_modules/babel-traverse/lib/path/context.js:76:18) at NodePath.call (/Users/ericlin/projects/360/node_modules/babel-traverse/lib/path/context.js:48:17) at NodePath.visit (/Users/ericlin/projects/360/node_modules/babel-traverse/lib/path/context.js:118:8) at TraversalContext.visitQueue (/Users/ericlin/projects/360/node_modules/babel-traverse/lib/context.js:167:16) @ ./app/routes.js 31:11-38

回答

2

我今天也有類似的情況在做清潔NPM安裝在舊的項目之後。看來babel-plugin-rewire是責怪。就我而言,我找到了兩種解決方案。

首先解決辦法是從捲回[email protected]1.0.0-rc-4

我選擇其他的解決方案,這可能是不適合你的情況。在我的.babelrc我有rewire插件聲明在頂級,所以我把它移到test環境。所以,我的我的.babelrc

{ 
    "presets": [ 
    "es2015", 
    "react" 
    ], 
    "plugins": [ 
    "syntax-class-properties", 
    "transform-class-properties", 
    "syntax-object-rest-spread", 
    "transform-object-rest-spread", 
    "rewire" 
    ], 
    "env": { 
    "start": { 
     "presets": [ 
     "react-hmre" 
     ] 
    } 
    } 
} 

改成這樣:

{ 
    "presets": [ 
    "es2015", 
    "react" 
    ], 
    "plugins": [ 
    "syntax-class-properties", 
    "transform-class-properties", 
    "syntax-object-rest-spread", 
    "transform-object-rest-spread" 
    ], 
    "env": { 
    "start": { 
     "presets": [ 
     "react-hmre" 
     ] 
    }, 
    "test": { 
     "plugins": [ 
     "rewire" 
     ] 
    } 
    } 
} 
+0

回滾到巴別塔 - 插件,重新連接感謝1.0.0-RC-4爲我工作! – Pakage