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

transform-react-constant-elements => Acorn: SyntaxError: Unexpected token #5325

Closed
slorber opened this issue Feb 16, 2017 · 13 comments
Closed
Labels
area: react i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@slorber
Copy link

slorber commented Feb 16, 2017

Input Code

Here's the exact input code I'm using: gist

I've tried to reduce/isolate the problematic part but was unable to find it. It seems that removing code blocks can somehow randomly make the compilation step pass successfully, don't know why.

Note that removing the whole component StampleDescriptionMainMediaAndText does make the error disappear, but I'm unable to identify which part of it is problematic, and surprisingly, removing other code blocks might also work!

Expected Behavior

Enabling plugin transform-react-constant-elements (latest) should work.

Current Behavior

ERROR in ./src/components/stample/stampleDescription/stampleDescription.js
Module parse failed: /Users/sebastienlorber/Desktop/Stample-react/node_modules/react-hot-loader/index.js!/Users/sebastienlorber/Desktop/Stample-react/node_modules/babel-loader/lib/index.js!/Users/sebastienlorber/Desktop/Stample-react/src/components/stample/stampleDescription/stampleDescription.js Unexpected token (348:85)
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected token (348:85)
    at Parser.pp$4.raise (/Users/sebastienlorber/Desktop/Stample-react/node_modules/acorn/dist/acorn.js:2221:15)
    at Parser.pp.unexpected (/Users/sebastienlorber/Desktop/Stample-react/node_modules/acorn/dist/acorn.js:603:10)
    at Parser.pp$2.parseBindingAtom (/Users/sebastienlorber/Desktop/Stample-react/node_modules/acorn/dist/acorn.js:1417:12)
    at Parser.pp$2.parseMaybeDefault (/Users/sebastienlorber/Desktop/Stample-react/node_modules/acorn/dist/acorn.js:1455:25)
    at Parser.pp$2.parseBindingList (/Users/sebastienlorber/Desktop/Stample-react/node_modules/acorn/dist/acorn.js:1440:27)
    at Parser.pp$1.parseFunctionParams (/Users/sebastienlorber/Desktop/Stample-react/node_modules/acorn/dist/acorn.js:1072:24)
    at Parser.pp$1.parseFunction (/Users/sebastienlorber/Desktop/Stample-react/node_modules/acorn/dist/acorn.js:1064:10)
    at Parser.pp$3.parseExprAtom (/Users/sebastienlorber/Desktop/Stample-react/node_modules/acorn/dist/acorn.js:1810:19)
    at Parser.pp$3.parseExprSubscripts (/Users/sebastienlorber/Desktop/Stample-react/node_modules/acorn/dist/acorn.js:1715:21)
    at Parser.pp$3.parseMaybeUnary (/Users/sebastienlorber/Desktop/Stample-react/node_modules/acorn/dist/acorn.js:1692:19)
 @ ./src/components/stample/stampleMainContentReadOnly/stampleMainContentReadOnly.js 29:26-93

Your Environment

    "babel-core": "6.23.1",
    "babel-loader": "6.3.2",
    "babel-plugin-transform-react-constant-elements": "6.23.0",
    "babel-plugin-transform-react-inline-elements": "6.22.0",
    "babel-plugin-transform-react-pure-class-to-function": "1.0.1",
    "babel-plugin-transform-react-remove-prop-types": "0.3.2",
    "babel-preset-react-app": "2.1.0",
    "babel-preset-stage-0": "6.22.0",
{
  "presets": [
    "react-app",
    "stage-0"
  ],
  "env": {
    "production": {
      "plugins": [
        "transform-react-constant-elements",
        "transform-react-inline-elements",
        "transform-react-remove-prop-types",
        "transform-react-pure-class-to-function"
      ]
    }
  },
  "sourceMaps": false
}

Maybe related to #5315 ? cc @STRML @existentialism

@babel-bot
Copy link
Collaborator

Hey @slorber! We really appreciate you taking the time to report an issue. The collaborators
on this project attempt to help as many people as possible, but we're a limited number of volunteers,
so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
community that typically always has someone willing to help. You can sign-up here
for an invite.

@existentialism
Copy link
Member

existentialism commented Feb 16, 2017

@slorber do you by chance use webpack's expose-loader?

(https://twitter.com/jimbolla/status/831525123182227458)

@hzoo
Copy link
Member

hzoo commented Feb 16, 2017

If you are getting an acorn error it's probably not babylon (unless we didn't compile something down to ES5 and thus the error)

@slorber
Copy link
Author

slorber commented Feb 16, 2017

@existentialism no I'm not using expose-loader

@hzoo this error only happens once I enable transform-react-constant-elements, it does not when I disable it, so it looks to me quite related to Babel no?

@hinok
Copy link

hinok commented Feb 23, 2017

@slorber @hzoo I encountered today the same problem. I made a sample repository that shows this bug (newest webpack, babel-*).

https://github.com/hinok/babel-loader-bug

ERROR in ./src/index.js
Module parse failed: /Users/dk/Desktop/Dev/babel-loader-bug/node_modules/babel-loader/lib/index.js!/Users/dk/Desktop/Dev/babel-loader-bug/src/index.js Unexpected token (23:37)
You may need an appropriate loader to handle this file type.
| };
|
| var bazFactory = function bazFactory((_temp = _ref3, _ref4 = <Bar icon={icon}>
|       {text}
|     </Bar>, _temp)) {

In my case this kind of code break babel-plugin-transform-react-constant-elements.

const Foo = ({ children }) => <div>{children}</div>;
const Bar = ({ icon, children }) => <div>{icon}{children}</div>;

const bazFactory = ({ text, icon }) => props => (
  <Foo {...props}>
    <Bar icon={icon}>
      {text}
    </Bar>
  </Foo>
);

const App = () => (
  <div>
    {bazFactory({ text: 'Hello World', icon: 'An icon' })()}
  </div>
);

I think that code is wrongly transformed

var bazFactory = function bazFactory((_temp = _ref3, _ref4 = <Bar icon={icon}>

It works when this plugin is removed from .babelrc.

@slorber
Copy link
Author

slorber commented Feb 23, 2017

great :) I'm sure it'll be way more helpful that my code snippet :p thanks

@zackify
Copy link

zackify commented Feb 24, 2017

I'm having the same problem. Removing babel-plugin-transform-react-constant-elements fixes it.

@hoschi
Copy link

hoschi commented Mar 20, 2017

Same error, slightly other syntax:

import React from 'react';
import renderIf from 'render-if';

export let Person = ({showButtons, buttonText}) => {
    return <div>
               This is me!
               { renderIf(showButtons)(() => (
                     <button>
                         { buttonText }
                     </button>
                 )) }
           </div>;
};

export default Person;

It works if I remove the plugin, or remove {buttonText}. This version works too:

import React from 'react';
import renderIf from 'render-if';

export let Person = ({showButtons, buttonText}) => {
    return <div>
               This is me!
               { renderIf(showButtons)(<button>
                                           { buttonText }
                                       </button>
                 ) }
           </div>;
};

export default Person;

@brantphoto
Copy link

hi everyone. I was having the same issue as @hinok,
var bazFactory = function bazFactory((_temp = _ref3, _ref4 = <Bar icon={icon}>

thought it was a version issue, but it appears to be an issue with the order of the plugins run

DOES NOT WORK:

    "plugins": [
      "transform-react-remove-prop-types",
      "transform-react-constant-elements",
      "transform-react-inline-elements"
     ]

DOES WORK:

    "plugins": [
      "transform-react-remove-prop-types",
      "transform-react-inline-elements"
      "transform-react-constant-elements"
    ]

while the documentation on https://babeljs.io/docs/plugins/transform-react-constant-elements/ does make a small reference to the "transform-react-constant-elements" step being perhaps last (e.g., just before minifying your code) it could be clearer that order matters. Or, perhaps they create a single react plugin that does all the optimization but enforces the order.

Did this help fix anyone's problems?

@slorber
Copy link
Author

slorber commented Apr 6, 2017

@brantphoto thanks, declaring constant-elements last seems to fix the problem on my codebase too!

There's already an optimization preset for Babel and I've made a PR to update the order: jamiebuilds/babel-react-optimize#33

Still, I think it's worth letting this bug open as order should probably not matter no?

@hinok
Copy link

hinok commented Apr 6, 2017

@brantphoto Thanks! This really helped me and and fixed the problem 🍾 🎈 🎉

@apaatsio
Copy link

apaatsio commented May 9, 2017

I believe this has been fixed by #5686

At least I couldn't reproduce @hinok's example any more.

Edit: I can't reproduce the error in @hoschi's example either.

@hoschi
Copy link

hoschi commented May 9, 2017

@apaatsio thanks for testing, I put it on my todo list

petrhanak added a commit to petrhanak/react-boilerplate that referenced this issue Nov 8, 2017
gretzky pushed a commit to react-boilerplate/react-boilerplate that referenced this issue Dec 28, 2017
* Merge v3.5 release (#1929)

* Docs Update: sass.md | New webpack version -loader suffix (#1484)

* New webpack version -loader suffix

New webpack version no longer allowed to omit the '-loader' suffix when using loaders.

* Webpack 2 migration module.loaders => module.rules

* Fix Loaders/Rules

* chore(docs): fix link to redux-saga docs

Fix a broken link to redux-saga docs.

* feat(webpack): Support OpenType fonts with .otf file extension (#1471)

* chore(docs): improve testing documentation

* [doc] improve code snippet syntax in unit-testing doc

linted code snippet and removed uneeded import

* [doc] add overview of reducer test in unit testing doc

add the completed reducer test file as overview in unit testing documentation

* [doc] improve component testing doc

linted code snippets, added complete test file as refernce and link to next doc page.

* chore(setup): remove LGTM config files (#1317)

* chore(setup): remove LGTM

* Add collaborating guidelines

* Add @KarandikarMihir

* Remove .react.js extensions (#1469)

* Remove .react.js extensions

* Restore file names in the title comments

* Remove hyphens

* chore(deps): update deps roll-up Jan-21-2017 (#1501)

* fix(tests): Replace sinon restore (#1512)

* Remove sinon.restore()

* Lock down sinon version

* chore(all): move to an organisation on GitHub

* Make webpack build less verbose (#1510)

* removed route names from app/routes (#1509)

* removed route names from app/routes

* removed name prop from internals/templates/routes

* removed name from internals/gens/route/route.hbs and routeWithReducer.hbs

* fix(eslint): Enable rule react/no-array-index-key (#1521)

* enable rule react/no-array-index-key

* fix test of List component

* fix(dependencies.js): clean up console clutter for install scripts (#1532)

Ref #1506

* Fix typo i18n.md (#1541)

* chore(deps): update deps roll-up Jan-28-2017 (#1531)

* chore(deps): update deps roll-up Jan-28-2017

* Update package.json

* Set history@3.2.1

* Using optimised version of the banner (#1560)

Taken from #907

* test(build:clean script): remove test:clean from build:clean - fixes coveralls reporting? (#1563)

* Update docs (README.md, Gotchas.md) (#1534)

* Update README.md

* Update gotchas.md

* Add links to gotchas

* Update docs

* Remove redundant sentence

* Move reinstall steps to gotchas.md

* Update README.md

* Minor corrections

* Add jest cache clean to gotchas.md

* Fix team of devs link (#1566)

* chore(deps): update deps roll-up Feb-04-2017 (#1561)

* Add iOS home screen icon (#1585)

* fix manifest icons (#1568)

* manifest(fix) (#1594)

* Change dev source map style (#1559)

* (fix) ProgressBar state error (#1553)

* Bind listener to the current instance of component

* Bring up coverage

* Reassign listener with newly bound listener

* Minor changes

* Separated dev and prod middlewares (#1556)

* Update FAQ with Styles getting overridden (#1592)

* Improve <List> tests (#1134)

* Fix imported styles (#1599)

* Migrate webpack loaders

* Add comment to CSS loader
This should help clarify and reduce common problems

* Split css rules into two

* Updated docs

* First draft of new styling docs

* Fix Sass heading

* Fix links and wording

* Add LESS and other improvements

* Post test fixes

* Updated headings and added more info section

* fix: Intl polyfill for language generator (#1611)

* fix: Intl polyfill for language generator
* fix: appveyor chrome issue by adding suggested --ignore-checksums

* Fix broken link in documentation. Fixes #1638. (#1643)

* refactor(react-router-scroll): Import only useScroll (#1609)

* chore(package.json): sort ESLint config (#1660)

This PR will sort the ESLint configuration alphabetically in `package.json`.

* Fix iOS home screen icons (#1604)



* Use absolute paths

* AppVeyor install chrome ignoring checksums

* Add Stateless Functions to Container Generator (#1494)

* Add Stateless Functions to Container Generator

* Fix linting test for generators

* Tightened up generator type names

- Also made component and container use similar order and language

* Fix odd node5 issue

* and disable eslint for the var

* Fix missing reference (#1725)

* Moving Contrib documentation to the right place (#1721)

* refactor(react-router): Import only necessary components (#1608)

Instead of importing the entire library, cherry-pick the components we use.
This is [supported and encouraged](https://github.com/ReactTraining/react-router/blob/master/docs/guides/MinimizingBundleSize.md) by react-router.

Reduced the size of the main bundle by 9 KB (709 KB -> 700 KB).

* Fixing links for the contributing.md (#1738)

* a grammatical item (#1740)

* Remove state update in componentWillUpdate (#1769)

* syntatical improvements to progress bar (#1633)

* syntatical improvements to progress bar

* declare propTypes and defaultProps on the class instead of using the static keyword

* Improve the setup to recognize our own repo before clearing it. (#1720)

* Add intelligence to the setup to recognize our own repo, before nuking it. (#760, #1719)

* Cleaning up console messages upon setup

* Adding a prompt for deciding whether to clear the repo or not. Fixed: #760, #1719

* Fixing the scenario where it was not exiting this file after not removing the repository

* Doing minor changes suggested

* Updating quickstart file location (#1712)

* Request utils: handle 204 and 205 HTTP response (#1780)

* feat(core): styled-components v2 update (#1775)

* feat(core): styled-components v2 update

* fix(deps): lock version for styled plugin

* Fix: Use local instance of shelljs (#1782)

* Use local instance of shelljs

* Replace var with const

* Switching deprecated babel-preset-latest to babel-preset-env (#1736)

* adding babel-preset-env package

* replacing deprecated babel-preset-latest with babel-preset-env

to avoid the following npm installation warning:
```
npm WARN deprecated babel-preset-latest@6.24.0:
preset-latest accomplishes the same task as babel-preset-env.
Please install it with 'npm install babel-preset-env --save-dev'.
'{ "presets": ["latest"] }' to '{ "presets": ["env"] }'.
For more info, please check the docs: http://babeljs.io/docs/plugins/preset-env
```

Ref. #1667

* removing deprecated babel-preset-latest package

* Add missing word (#1789)

* Migrating from React.PropTypes to PropTypes (#1787)

* adding prop-types dependency

* migrating from React.PropTypes to PropTypes

* Adding some tests (#1784)

* tests(FeaturePage): testing shouldComponentUpdate function

* tests(HomePage): testing if username prop is missing

* tests(ProgressBar): testing when route is not changing

* tests: removing global-styles.js from coverage collect

* tests(Toggle): adding tests for empty values prop

* tests(store): adding missing tests

* tests(ProgressBar): adding missing tests

* chore(deps): update deps roll-up Jun-01-2017 (#1794)

* chore(deps): update deps roll-up Jun-01-2017

* Add react-test-renderer as dev dependency

* Remove `react-addons-test-utils`

* Use new `react-helmet` API

* Get rid of the warning: 'DeprecationWarning: loaderUtils.parseQuery() received a non-string value which can be problematic, see webpack/loader-utils#56 parseQuery() will be replaced with getOptions() in the next major version of loader-utils.'
Get rid of the warning: 'DeprecationWarning: loaderUtils.parseQuery() received a non-string value which can be problematic, see webpack/loader-utils#56 parseQuery() will be replaced with getOptions() in the next major version of loader-utils.'

* Revert line that wasn't meant to be commited

* docs(maintenance): Create dependency update doc (#1790)

* docs(maintenance): Create dependency update doc

* Update dependency.md

* Update dependency.md

* Update dependency.md

* Update dependency.md

* Add link to #598

* Update the 'tagged template literals' link to point to its new home at styled-components.com (#1824)

* feat(core): React Router v4, React-Loadable, asyncInjectors (#1746)

* Migrate to react router v4.

* Make sure Switch renders after redux state change by passing in redux location, propagate computedMatch to Route, and make not-found matcher non-exact.

* Fix route generator.

* Implicitly pass store into loader from AsyncRoute to simplify custom child route components.

* Fix route prop propagation.

* Regen yarn.lock

* Keep track of route loading in redux state and read in progress bar.

* Replace AsyncRoute with react-loadable

* Add `DefaultLoadingComponentProvider`

* Rename `loader.js` to `Loadable.js`

* Revert 9f44f1b

* small chores

* Add tests

* Update generators

* Exclude component/Loadable from coverage

* Update docs

* Make App a class that extends React.Component to enable hot reloading

* Add a link to RR4 API

* Improve generators

* Fix linting errors

* Update react-loadable

* Update yarn.lock

* Propagate InnerLoadable props to the rendered component, for Route props like match.

* Refactor

* rename withMappedState -> withConnect

* rename name to key

* Use constants

* Make 'daemon' a default mode for `injectReducer`

* Simplify `ejectSaga`

* Improve docs

* clean up

* recommend to use `ConnectedSwitch`

* turn `App` into a function like it was before

* Run CI

* Import `memoryHistory` and `browserHistory` from `react-router-dom` instead of `react-router`

* Remove path from a 'not found' route

* Update deps

* Simplify tests

* Remove modes from `injectReducer`

* Make second argument to be a descriptor in `sagaInjectors`

* Change `constants` to have consistent values

* Remove non-daemon saga descriptors in production in `ejectSaga`

* Save an entire descriptor in the saga registry

* Fix `constants` in templates

* fix(hmr): Replace `preset-hmre` with vanilla webpack HMR (#1871)

* Replace react-hmre with bare webpack hmr

* Explicitly unmount the main component

* Prevent recomputing reducers for `replaceReducer`

* Add a link to Wepack HMR to the docs

* Remove `overlay=true`

* Accept an array of modules to hot reload

* Add Debugging section in Docs + VS Code instructions (#1698)

* Add debugging section in README

* Move WebStorm FAQ to debugging section

* Add VS Code to debugging section

* Update VS Code launch config

* Update VS Code config to work in dev branch

* Add VS Code launch.json config

* Update launch.json to be compatible with master

* Update VS Code launch to be compatible with master

* Remove .vscode launch config

* Add notice on source map issue for VS Code.

* move onSubmitForm test into mapDispatchToProps test (#1644)

* Use camelcase for reducer and saga key to match selector. (#1888)

* chore(deps): remove unusable deps sinon (#1882)

* chore(deps): downgrade `sanitize.css` (#1872)

* chore(templates): turn `App` into a functional component (#1892)

Fixes #1884

* fix(generators): use correct selector names in tests and regular selectors should not be nested (#1873)

* Rename store.js to configureStore.js to Prevent conflict with storeJS… (#1904)

* Rename store.js to configureStore.js to Prevent conflict with storeJS npm package

* Fix store -> configureStore

* Bump webpack to 3.0.0 and update related deps (#1823)

* Bump webpack to 3.0.0 and related deps

* Add ModuleConcatenationPlugin to webpack base config

* Check in mysterious change in yarn.lock

* Install latest html-webpack-plugin and resolve incorrect peer dep issue

* Update webpack to 3.5.4

* Bump webpack to 3.5.5

* Move ModuleConcatenationPlugin from base to prod config, add  --display-optimization-bailout flag

* Serve Dlls via add-asset-html-webpack-plugin (#1849)

* Serve Dlls via add-asset-html-webpack-plugin

* Remove duplicate dll script tags and cheerio dependency

* Remove cheerio refs from docs

* Minor whitespace change

* Remove eslint exception in webpack.dll.babel.js

* chore(deps): Upgrade React to v15.6 (#1832)

* chore(deps): regenerate `yarn.lock` (#1931)

* chore(deps): regenerate `yarn.lock`

* Empty commit to restart netlify

* chore(3.5): Update changelog.md

* chore(deps): Bump version to 3.5.0

* fix(internals): Update RBP version string in internal config (#2002)

closes #2001

* Correct babel plugin order

here is related issue comment:
babel/babel#5325 (comment)

* fix incorrect merge
smspillaz added a commit to smspillaz/intuitive-math that referenced this issue Dec 29, 2017
nl0 added a commit to nl0/quilt that referenced this issue Feb 19, 2018
transform-react-constant-elements babel blugin should be last in the
pipeline: babel/babel#5325
akarve pushed a commit to quiltdata/quilt that referenced this issue Feb 21, 2018
* test

* refactor profile page components into smaller components

* lint and ui wip

* add member

* disable linter for select lines

* break admin into dedicated component

* demo ui wip

* UI Demo v1

* flush merge resolution

* eliminate hardcoded team used for testing

* update yarn.lock

* package.json: add recompose

* update docker files for local catalog

* remove dead env file

* Pagination component

* upgrade enzyme, add enzyme wrapper serialization via enzyme-json

* Pagination: basic tests

* PackageList: pagination

* document running catalog locally

* update code block style

* update admin views; add package-lock.json

* new lock file; debug comment in config

* regenerate package-lock.json

* containers/Admin: fix prop-types reference

* containers/Admin: get members from the api

* app/constants/api: apiStatus prop type

* containers/Admin: further work (still WIP)

* containers/Admin: further work (still WIP)

* containers/Admin: further work (still WIP, but kinda working)

* add redux-form dependency

* app/utils: add validators lib

* app/reducers: add redux-form reducer

* app/containers/Admin: form for adding members

* some fixes and cleanup

* container/Admin: add member form & stuff

* util/validators: rm unneeded validators

* add uuid dep

* Notifications container

* use Notifications

* app/containers/Admin: actions

* lint, muffle tests

* Document how to update Docker images [ci skip]

* fix `npm run build`

transform-react-constant-elements babel blugin should be last in the
pipeline: babel/babel#5325

* add classnames dep

* components/MIcon: fix className override

* containers/Admin: activity indication, confirms & stuff

* containers/Admin: reuse ErrorMessage component

* containers/Admin: muffle eslint warnings

* package.json: tweak linter rules to work with react-router Link

* containers/Admin: tweaks, refactoring, cleanup

* containers/Admin: i18n & stuff

* containers/Profile: public -> team section for team instances

* containers/{Admin,Profile}: requested changes

* containers/Admin: more i18n, brevity
@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label May 4, 2018
@lock lock bot locked as resolved and limited conversation to collaborators May 4, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: react i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

No branches or pull requests

10 participants