Skip to content
This repository has been archived by the owner on Jan 18, 2021. It is now read-only.

_typeof is not a function on commonjs import #87

Open
topaxi opened this issue Apr 16, 2017 · 2 comments
Open

_typeof is not a function on commonjs import #87

topaxi opened this issue Apr 16, 2017 · 2 comments

Comments

@topaxi
Copy link
Contributor

topaxi commented Apr 16, 2017

I'm trying to import clipboard from npm. This results in _typeof is not a function which seems to be a function defined by babel to support es2015 symbols.

The imported module is plain JavaScript so babel transpilation seems unnecessary to me (but we might not know this while importing). I think it might be some rollup issue where _typeof is wrongly hoisted?

My ember-cli-build.js configuration:

'use strict';

const GlimmerApp = require('@glimmer/application-pipeline').GlimmerApp;
const resolve = require('rollup-plugin-node-resolve');
const commonjs = require('rollup-plugin-commonjs');

module.exports = function(defaults) {
  let app = new GlimmerApp(defaults, {
    rollup: {
      plugins: [
        resolve({ jsnext: true, module: true, main: true }),
        commonjs()
      ]
    }
  });

  return app.toTree();
};

My component definition:

import Component from '@glimmer/component';
import Clipboard from 'clipboard/dist/clipboard';

export default class TmpyClipboard extends Component {
  args: { content: string };

  didInsertElement() {
    let clipboard = new Clipboard(this.element, {
      text: () => this.args.content
    });
  }
};
@daveli
Copy link

daveli commented Apr 18, 2017

@topaxi This is caused by double transpiling code. As recommended by documentation of https://github.com/rollup/rollup-plugin-babel you should exclude node_modules e.g:

'use strict';

const GlimmerApp = require('@glimmer/application-pipeline').GlimmerApp;
const babel = require('rollup-plugin-babel');
const resolve = require('rollup-plugin-node-resolve');
const commonjs = require('rollup-plugin-commonjs');

module.exports = function(defaults) {
  let app = new GlimmerApp(defaults, {
    rollup: {
      plugins: [
        babel({
          exclude: 'node_modules/**'
        }),
        resolve({
          jsnext: true,
          module: true,
          main: true
        }),
        commonjs()
      ]
    }
  });

  // Use `app.import` to add additional libraries to the generated
  // output files.
  //
  // If you need to use different assets in different
  // environments, specify an object as the first parameter. That
  // object's keys should be the environment name and the values
  // should be the asset to use in that environment.
  //
  // If the library that you are including contains AMD or ES6
  // modules that you would like to import into your application
  // please specify an object with the list of modules as keys
  // along with the exports of each module as its value.

  return app.toTree();
};

@topaxi
Copy link
Contributor Author

topaxi commented Apr 18, 2017

Nice this works!

We should probably make this easier to use or put some documentation on this on glimmerjs.com

Let me know how I can help out with this.

digitalkaoz added a commit to digitalkaoz/react-static that referenced this issue Sep 26, 2018
react-static@ad87562 introduced some double compiling.
like here: glimmerjs/glimmer-application-pipeline#87

so excluding `node_modules` we must!
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants