Skip to content
This repository was archived by the owner on Aug 4, 2021. It is now read-only.
This repository was archived by the owner on Aug 4, 2021. It is now read-only.

'import' and 'export' may only appear at the top level #90

@marvinhagemeister

Description

@marvinhagemeister

I'm having trouble bundling handlebars. On bundling I get the following error:

Error parsing /myproject/node_modules/handlebars/dist/cjs/handlebars/no-conflict.js: 'import' and 'export' may only appear at the top level (4:0) in /myproject/node_modules/handlebars/dist/cjs/handlebars/no-conflict.js

My first try to fix this, was to use the named exports feature. But although I've explicitly specified handlebars as a named export, it seems to be ignored and I always get the same error message as above.

Here is my setup:

// rollup.config.js
const rollup = require('rollup');
const babel = require('rollup-plugin-babel');
const replace = require('rollup-plugin-replace');
const commonjs = require('rollup-plugin-commonjs');
const globals = require('rollup-plugin-node-globals');
const nodeResolve = require('rollup-plugin-node-resolve');

export default {
  entry: 'scripts/main.js',
  dest: 'public/assets/js/bundle.js',
  format: 'iife',
  moduleName: 'test',
  sourceMap: true,
  plugins: [
    globals(),
    nodeResolve({
      jsnext: true,
      main: true,
      browser: true,
      preferBuiltins: false
    }),
    commonjs({
      include: ['node_modules/**'],
      namedExports: {
        'node_modules/handlebars/dist/handlebars.min.js': ['handlebars']
      }
    }),
    babel({
      exclude: ['node_modules/**'],
      runtimeHelpers: true
    }),
    replace({
      'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
    })
  ]
}
// main.js
import Handlebars from 'handlebars';

console.log(Handlebars.compile('<h1>Hello World</h1>');
// .babelrc
{
  "presets": [
    ["es2015", {
      "modules": false
    }]
  ],
  "plugins": [
    "external-helpers",
    "transform-object-rest-spread"
  ]
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions