0

I am doing a test app that is all es6 ... and i hit a bump when using this plugin ... the docs say to use this to configure the plugin and it works:

var getBabelRelayPlugin = require('babel-relay-plugin');
var schemaData = require('../data/schema.json').data;
module.exports = getBabelRelayPlugin(schemaData, {
  abortOnError: true
});

can anyone tell me why this syntax does not work?

"use strict";

import getBabelRelayPlugin from 'babel-relay-plugin';
import schemaData from '../data/schema.json';

export default getBabelRelayPlugin(schemaData.data, {
  abortOnError: true
});

thanks

loganfsmyth
  • 156,129
  • 30
  • 331
  • 251
Wowzaaa
  • 3,730
  • 4
  • 21
  • 23

1 Answers1

0

In the first case, to import your plugin using the standard CommonJS require you can write:

var myBabelRelayPlugin = require('./myBabelRelayPlugin.js');

But in the ES6 case if your module was transpiled by Babel 6, you have to add .default at the end:

var myBabelRelayPlugin = require('./myBabelRelayPlugin.js').default;

Most probably Babel does not try to add .default when loading plugins, so it cannot load ES6 version of your plugin correctly.

dened
  • 4,253
  • 18
  • 34
  • thanks dened for your input ... i asked if ur answer is correct on the github forum and will mark it as the right answer when i get a feedback from them :) – Wowzaaa Feb 16 '16 at 10:19
  • This is really a Babel question, not a Relay question. Mark as correct if it works? – Joe Savona Feb 16 '16 at 16:35
  • There's more info on this at http://stackoverflow.com/questions/33505992/babel-6-changes-how-it-exports-default – Joe Savona Feb 16 '16 at 17:18