Gatsby: `src/data` can't use es6 module import/exports?

Created on 23 Mar 2018  路  1Comment  路  Source: gatsbyjs/gatsby

not sure if this is by design but this code:

import file from './file';
export default [file];

gives this error:

 Error: /file/index.js:1
  (function (exports, require, module, __filename, __dirname) { import file from './file';
                                                                ^^^^^^
  SyntaxError: Unexpected token import

but this works great!

const file = require('./file');
module.exports = [file];

At the bottom of this doc, it says putting a file within a src subdir will allow you to write es6. (https://www.gatsbyjs.org/docs/plugin-authoring/#local-plugins)

Is this by design or maybe I'm missing something?

Most helpful comment

you can place the files in a src subfolder and build them to the plugin folder root

You need a build step as the last part of that sentence describes. Node.js won't support import/export until Node 10 and only then in .mjs files.

>All comments

you can place the files in a src subfolder and build them to the plugin folder root

You need a build step as the last part of that sentence describes. Node.js won't support import/export until Node 10 and only then in .mjs files.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dustinhorton picture dustinhorton  路  3Comments

dustinhorton picture dustinhorton  路  3Comments

timbrandin picture timbrandin  路  3Comments

theduke picture theduke  路  3Comments

benstr picture benstr  路  3Comments