0

I am currently trying to create a webapp with React, and I am trying to make a request to my server (with request). However, whenever I try to webpack the app I get an error. I am almost certain it has to do with request having to be labeled as an external library, but I can't get it to work. Can anybody help me?

Here is my webpack config.

var webpack = require('webpack');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var extractCSS = new ExtractTextPlugin();

module.exports = {
    entry : [
        './js/index.js'
    ],
    output : {
        path : __dirname + '/lib/',
        publicPath : 'http://localhost:8080',
        filename : 'bundle.js'
    },
    plugins : [
        new ExtractTextPlugin('app.css'),
        new webpack.NoErrorsPlugin()
    ],
    module : {
        loaders : [
            {
                test : /\.js$/,
                loaders : [
                    'babel'
                ],
                exclude : /node_modules/
            },
            {
                test : /\.(jpe?g|png|gif|svg)$/i,
                loaders : [
                    'url?limit=8192',
                    'img'
                ]
            },
            {
                test : /\.scss$/,
                include : /styles/,
                loader : extractCSS.extract([
                    'css',
                    'autoprefixer',
                    'sass'
                ])
            }
        ]
    },
    resolve : {
        extensions : ['', '.js', '.json']
    },
    externals : {
        request : 'request'
    }

};

and here is the error that I am getting

ERROR in ./js/services/comic
Module parse failed: /Users/matthew.pfister/IdeaProjects/web/js/services/comic    Line 1: Unexpected token
You may need an appropriate loader to handle this file type.
| import request from 'request';
| 
| export default {
   @ ./js/creators/comic.js 11:21-49

Here is the file it is referencing

import request from 'request';

export default {
  ...
};
HerrPfister
  • 67
  • 1
  • 2
  • 7

2 Answers2

0

I dont think export default {...} is valid. try

var o = {...}
export default o 

should work.

ThrowsException
  • 2,586
  • 20
  • 37
0

I just realized that the file that is throwing the error doesn't have the .js extension.

::facepalm:: everything is fixed.

HerrPfister
  • 67
  • 1
  • 2
  • 7
  • that'll do it. Did the `export default {}` syntax actually work? I remember reading a while back that objects had to be two liners and didn't work that same as `export default function` or `export default class` – ThrowsException Mar 28 '16 at 02:09
  • Actually there is code between the curly braces. I just used the ellipses to avoid polluting the question with unnecessary code. Sorry for the confusion. – HerrPfister Mar 29 '16 at 03:17