sandpack icon indicating copy to clipboard operation
sandpack copied to clipboard

Sandpack bundler incorrectly transpiles destructuring syntax with a default expression in an `export` declaration

Open alessbell opened this issue 2 years ago • 0 comments

Bug report

Packages affected

  • [ ] sandpack-client
  • [ ] sandpack-react
  • [x] sandpack bundler - let me know if this issue should be moved elsewhere :)

Description of the problem

When running a Codesandbox in the browser using the Sandpack bundler, the library optimism is incorrectly transpiled (reproducible at version 0.17.2), resulting in the TypeError (0 , $csb___helpers_js.toArray) is not a function.

The source in optimism/lib/helpers.js is using destructuring syntax with a default expression in an export declaration; I cannot reproduce the issue when running the app locally with Webpack.

What were you doing when the problem occurred?

Creating a Codesandbox using @apollo/[email protected] which has a dependency on [email protected].

What steps can we take to reproduce the problem?

CleanShot 2023-05-17 at 14 29 07

Open the linked sandbox to view the error. If you open the Chrome devtools, view the Sources tab, hit command + P to search/otherwise pull up the file optimism/lib/helpers.js, you'll see that toArray is never added as a property on exports.

If you download the sandbox as a zip and npm i && npm start, you'll notice the error doesn't happen when bundled with Webpack.

Link to sandbox: link

GitHub repository for the Codesandbox mirror: link

Your Environment

Software Name/Version
Sandpack-client version
Sandpack-react version
Browser Chrome
Operating System MacOS

alessbell avatar May 17 '23 18:05 alessbell