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

version 1.0.2 breaks webpack: 'return' outside of function #7

Closed
zaggino opened this issue Dec 17, 2019 · 4 comments
Closed

version 1.0.2 breaks webpack: 'return' outside of function #7

zaggino opened this issue Dec 17, 2019 · 4 comments

Comments

@zaggino
Copy link

zaggino commented Dec 17, 2019

Using 1.0.1 works but 1.0.2 breaks webpack build with:

Creating an optimized production build...
Failed to compile.

./node_modules/is-map/index.js
SyntaxError: /usr/app/node_modules/is-map/index.js: 'return' outside of function (12:1)

  10 | \t\treturn false;
  11 | \t};
> 12 | \treturn;
     | \t^
  13 | }
  14 | 
  15 | var $mapHas = $Map ? Map.prototype.has : null;
@ljharb
Copy link
Member

ljharb commented Dec 17, 2019

Top-level return has always been valid in node CJS modules. Webpack v4.31+ should have support for this pattern; what version are you using?

@ljharb
Copy link
Member

ljharb commented Dec 17, 2019

v2.0.1 of both is-map and is-set have been released.

@zaggino
Copy link
Author

zaggino commented Dec 17, 2019

@ljharb we're using create-react-app, version is react-scripts@3.3.0 which references webpack 4.41.2 https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/package.json#L79

@ljharb
Copy link
Member

ljharb commented Dec 17, 2019

@zaggino in CRA's case, the problem is caused by two things: 1) transpiling node_modules, which is highly unsafe, and 2) babel does not enable the allowTopLevelReturn by default, nor does CRA enable it, which makes transpiling all valid CJS modules impossible.

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