rollup/rollup-plugin-json

Unexpected Token

margaretjoanmiller opened this issue · 2 comments

Upon running the rollup config:

import babel from 'rollup-plugin-babel';
import json from 'rollup-plugin-json';
import nodeResolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';

export default {
  entry: 'server/server.js',
  format: 'umd',
  dest: 'bundelIndex.js',
  external: ['bluebird', 'knex', 'node-gyp', 'fsevents'],
  plugins: [
    babel({
      exclude: 'node_modules/**',
      babelrc: false,
      presets: ['react', 'es2015-rollup', 'stage-0'],
      plugins: ['transform-decorators-legacy'],
    }),
    json(),
    nodeResolve({ jsnext: true, main: true}),
    commonjs(),
  ],
};

I get the following error at runtime:

/Users/gigavinyl/Projects/ceres/server/assets.json: Unexpected token (1:5)
SyntaxError: /Users/gigavinyl/Projects/ceres/server/assets.json: Unexpected token (1:5)
{"js":"bundle.79f6da3830e25bcf5a6a.min.js"}

This appears to conform to the usage demonstrated in the README, what am I doing wrong here? Or is this an actual bug perhaps?

What @jonataswalker said – you could either run json before babel (recommended) or exclude .json files in the Babel config. I think the Babel plugin should also default to only including valid extensions as per #8