0

I'm new to Webpack. My React config works, but when I try to import postcssJs from 'postcss-js' the browser throws an Uncaught TypeError: Cannot read property 'Base64' of undefined in the bundle on var _Base64 = global.Base64;.

Here is my webpack config:

module.exports = {
  entry: './demo/js/components/App.js',

  output: {
    path: __dirname + '/demo/js',
    filename: 'bundle.js'
  },

  module: {
    loaders: [
      {
        test: /\.(js|jsx)$/,
        loader: 'babel',
        query: {
          presets: [
            'es2015',
            'stage-0',
            'react'
          ],
          plugins: [
            'transform-react-stateless-component-name'
          ]
        }
      }
    ]
  },

  node: {
    fs: 'empty'
  },

  watch: true
}

Here is the React file I'm having problems with:

import React from 'react'

import postcssJs from 'postcss-js' // When I comment out this line, everything works fine.

export default ({greeting}) => <h3>{greeting}</h3>

I'm sure I'm just missing some basic Webpack paradigm about using some sort of loader or something, but I can't figure it out.

I'd really appreciate any help as this has been blocking me for several hours now...


Here are my dependencies:

"dependencies": {
  "chalk": "^1.1.3",
  "postcss": "^5.2.5",
  "postcss-value-parser": "^3.3.0"
},
"devDependencies": {
  "babel-cli": "^6.18.0",
  "babel-loader": "^6.2.5",
  "babel-plugin-add-module-exports": "^0.2.1",
  "babel-plugin-transform-flow-strip-types": "^6.18.0",
  "babel-plugin-transform-react-stateless-component-name": "^1.0.1",
  "babel-preset-es2015": "^6.18.0",
  "babel-preset-react": "^6.16.0",
  "babel-preset-stage-0": "^6.16.0",
  "browser-sync": "^2.17.5",
  "imports-loader": "^0.6.5",
  "lodash": "^4.16.4",
  "npm-run-all": "^3.1.1",
  "postcss-js": "^0.1.3",
  "react": "^15.4.0-rc.4",
  "react-dom": "^15.4.0-rc.4",
  "stylus": "^0.54.5",
  "webpack": "^2.1.0-beta.25"
}

It works without Babel, but I need Babel...

corysimmons
  • 7,296
  • 4
  • 57
  • 65

0 Answers0