Skip to content

Uncaught SyntaxError: Unexpected token export #2049

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

Closed
stereobooster opened this issue Apr 30, 2017 · 4 comments
Closed

Uncaught SyntaxError: Unexpected token export #2049

stereobooster opened this issue Apr 30, 2017 · 4 comments

Comments

@stereobooster
Copy link
Contributor

stereobooster commented Apr 30, 2017

Can you reproduce the problem with latest npm?

brew upgrade yarn
yarn --version
0.23.3
rm -rf node_modules
yarn install
yarn start

Description

Seeing following error in browser console:

Uncaught SyntaxError: Unexpected token export

Trying to export ES6 module from node_modules. Is it wrong webpack configuration or I miss something in ES6 syntax? File from which I'm trying to export looks like this:

// React Components
export {default as InteractiveMap} from './components/interactive-map';
export {default as StaticMap} from './components/static-map';
export {default as MapControls} from './components/map-controls';

Environment

npm ls react-scripts
[email protected] /Users/slavik/my/react-map-gl-test1
├── UNMET PEER DEPENDENCY [email protected]
└── [email protected]

npm ERR! peer dep missing: [email protected], required by [email protected]
node -v
v6.1.0
npm -v
3.8.6
  1. Operating system: Mac OS X El Capitan

Reproducible Demo

https://github.com/stereobooster/create-react-app-map-gl

@stereobooster
Copy link
Contributor Author

Error happens because latest CRA uses webpack 1. To use webpack 2: yarn add react-scripts@canary. See: #183 (comment)

@gaearon
Copy link
Contributor

gaearon commented May 1, 2017

This seems like a problem with the module you use, really. Publishing untranspiled ES6 modules as an entry point is not recommended, as it doesn’t work in Node or with older bundlers.

Additionally relying on canary releases of react-scripts is discouraged because they are known to contain bugs.

@stereobooster
Copy link
Contributor Author

stereobooster commented May 1, 2017

Publishing untranspiled ES6 modules as an entry point is not recommended, as it doesn’t work in Node or with older bundlers.

This lib provides both versions like this (source code):

  "main": "dist/index.js",
  "module": "dist-es6/index.js",
  "scripts": {
    "build-es5": "mkdir -p dist && babel src --out-dir dist --plugins=transform-es2015-modules-commonjs --source-maps inline",
    "build-es6": "mkdir -p dist-es6 && babel src --out-dir dist-es6 --source-maps inline",

@gaearon is it considered to be a bad practice?

PS I explicitly required ES6 module, without realisation that CRA stable still use webpack 1 instead of webpack 2

@gaearon
Copy link
Contributor

gaearon commented May 1, 2017

PS I explicitly required ES6 module, without realisation that CRA stable still use webpack 1 instead of webpack 2

Ah, I see! Then the library is fine. 👍
Thanks for explaining!

@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