Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ES6 -> ES5 in npm package #2

Closed
kachkaev opened this issue Feb 12, 2017 · 4 comments
Closed

ES6 -> ES5 in npm package #2

kachkaev opened this issue Feb 12, 2017 · 4 comments

Comments

@kachkaev
Copy link

I'm using create-react-app and its webpack config does not apply babel to stuff in node_modules. The app works in dev mode because Chrome understands ES6 pretty well already, but when I run yarn build, this error shows up:

Failed to compile.

static/js/main.582ff19c.js from UglifyJs
SyntaxError: Unexpected token: operator (>) [./~/neat-csv/index.js:6,0]

The reason is => in index.js, which is not expected. Could you please move from ES6 to ES5 in the published version?

Thanks for the wrapper! Saves some time re-implementing it in every new project :–)

@kachkaev
Copy link
Author

I temporary copied index.js to my src, so it goes through babel now:

// import neatCsv from 'neat-csv';
import neatCsv from './lib/neat-csv';

@kachkaev
Copy link
Author

Relevant discussion:
facebook/create-react-app#1125

@sindresorhus
Copy link
Owner

In short, no. Longer answer: sindresorhus/ama#446 (comment)

@kachkaev
Copy link
Author

Your package, your rules :–)

For those who also use create-react-app or a similar framework with a preconfigured webpack, here is what you can do:

  1. Create src/lib/neat-csv.js:

    /* eslint-disable */
    'use strict';
    const intoStream = require('into-stream');
    const csvParser = require('csv-parser');
    const getStream = require('get-stream');
    
    module.exports = (input, opts) => {
      if (typeof input === 'string' || Buffer.isBuffer(input)) {
        input = intoStream(input);
      }
    
      return getStream.array(input.pipe(csvParser(opts)));
    };
  2. replace import neatCsv from 'neat-csv'; with import neatCsv from '../lib/neat-csv' (the path may vary depending on your current file location).

  3. npm rm -S neat-csv; npm i -S into-stream csv-parser get-stream

  4. Enjoy :–)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants