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

error when requiring node modules that use destructuring #415

Closed
stopachka opened this issue Aug 10, 2016 · 2 comments
Closed

error when requiring node modules that use destructuring #415

stopachka opened this issue Aug 10, 2016 · 2 comments

Comments

@stopachka
Copy link

I have a node module, where in it's lib there is a file like so:

lib/foo.js

    const {APPID} = require('./config');

within App.js, when I require this module

    App.js
    const myModule = require('myModule/lib/foo')

Now, when I load this in the browser, an error is thrown

    Unexpected Token {

This is because webpack has required myModule/lib/foo.js, but has not done any processing on it -- the destructuring is not converted.

This makes sense, as it is indeed a node module outside of our app.

Is there a recommended solution to solve this? I could eject and try to update configuration, but am wishing there is another way

@stopachka
Copy link
Author

nevermind, am closing this, as I presume it would be against the spirit of create-react-app to allow this much customization. will eject and update the excludes regex

@gaearon
Copy link
Contributor

gaearon commented Aug 10, 2016

It is not recommended to run Babel on node_modules. This is known to break some libraries, and also is terribly slow. The ecosystem convention so far has been to precompile libraries to ES5 before shipping them to npm—at least for the libraries meant to be consumed in the browser.

@lock lock bot locked and limited conversation to collaborators Jan 22, 2019
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