babel/babel-standalone

Cannot read property 'TYPED_ARRAY_SUPPORT' of undefined

jeanbza opened this issue · 3 comments

When I npm install --save-dev babel-standalone and import 'babel-standalone', my browser console gives me:

screen shot 2017-01-18 at 11 19 08 am

Got it to work with exclude: /node_modules/ in our webpack.

May be worth writing up a small example of how to use webpack + babel-standalone + imports?

For anyone stumbling across this in the future, here's how we're doing it:

.babelrc

{
  "presets": ["es2015", "react"]
}

webpack.config.babel.js

import path from 'path'

export default {
  entry: './src/app.jsx',
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'bundle.js'
  },
  module: {
    rules: [
      {
        test: /\.js|.jsx$/,
        loader: 'babel-loader',
        exclude: /node_modules/,
      },
      {
        test: /\.css$/,
        use: ['style-loader', 'css-loader']
      },
      {
        test: /\.json$/,
        use: 'json-loader'
      }
    ]
  },
  node: {
    fs: 'empty',
  },
  devtool: 'inline-source-map'
}

app.jsx

import React from 'react'
import ReactDOM from 'react-dom'

import * as Babel from 'babel-standalone'

const handleClick = () => {
  console.log(Babel)

  var input = 'const getMessage = () => "Hello World";';
  var output = Babel.transform(input, { presets: ['es2015'] }).code;
  console.log(output)
}

const app = <div>
  <button onClick={handleClick}> click me</button>
  <div id="outputArea" style={{backgroundColor: 'red'}}>output area</div>
</div>

ReactDOM.render(app, document.getElementById('root'))

May be worth writing up a small example of how to use webpack + babel-standalone + imports?

I don't think this is a very common use case, hence there's not a lot of documentation around it 😃

@Daniel15 It's not? Isn't that what React's code editor and various other code editors use?