2016-07-22 90 views
0

當我使用webpack-dev-server時,一切正常。 但隨着「的WebPack」命令在服務器上部署我的應用程序時,我得到了以下錯誤:無法在webpack之後加載JSON:意外的令牌<位於位置0的JSON中

SyntaxError: Unexpected token < in JSON at position 0 
    at Object.parse (native) 
    at Object.<anonymous> (http://localhost:3389/bundle.js:24629:18) 
    at XMLHttpRequest.respond (http://localhost:3389/bundle.js:24499:32) 

我相信我所收到的是XML而不是JSON。我不知道該怎麼辦。我正在使用來自'd3-request'的請求加載我的JSON文件。我的webpack.config.js看起來像:

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

module.exports = { 
    context: path.join(__dirname, './app'), 
    entry: { 
    js: './index.js', 
    html: './index.html', 
    }, 
    output: { 
    path: path.join(__dirname, './static'), 
    filename: 'bundle.js', 
    }, 
    module: { 
    preLoaders: [ 
     { test: /\.json$/, loader: 'json'}, 
    ], 
    loaders: [ 
     { 
     test: /\.html$/, 
     loader: 'file?name=[name].[ext]' 
     }, 
     { 
     test: /\.css$/, 
     loaders: [ 
      'style-loader', 
      'css-loader?modules&sourceMap&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]', 
     ] 
     }, 
     { 
     // transpile es6/jsx code to es5 
     test: /\.(js|jsx)$/, 
     exclude: /node_modules/, 
     loaders: [ 
      'babel-loader' 
     ] 
     }, 
     { test: /\.json$/, 
     loader: "json-loader" 
     } 
    ], 
    }, 
    resolve: { 
    extensions: ['', '.js', '.jsx'] 
    }, 
    plugins: [ 
    new webpack.optimize.CommonsChunkPlugin('vendor', 'vendor.bundle.js'), 
    new webpack.DefinePlugin({'process.env': { 
     NODE_ENV: JSON.stringify(process.env.NODE_ENV || 'development') 
    }}) 
    ], 
    devServer: { 
    contentBase: './app', 
    hot: true 
    } 
} 
+0

你爲什麼要設置預加載器?任何特定的原因? –

+0

我試圖解決這個問題。我看到其他人使用這個設置。它沒有改變。 – Nauhc

+0

非常仔細地查看'bundle.js:24629:18'。有時檢查產生的包有助於這些。 –

回答

0

原來是服務器端的快速代碼。我不小心讓Express從我的index.html文件中輸入錯字。 webpack沒什麼問題。

相關問題